The behaviour you've seen editing your text file is to be expected.

Hard links are not commonly used on Windows. (They're not even that common in Unix - soft links seem to be more usual.) Thus some Windows software might not expect to be dealing with linked files and accidentally end up breaking the link - I'm guessing that's what's happening with your image editor.

Example scenario:

  1. You link x.jpeg and y.jpeg.
  2. You open y.jpeg in your image editor and make some changes.
  3. You click the save button.
  4. Internally, your image editor does the following:
    1. Saves the image as y.tmp
    2. Deletes y.jpeg
    3. Renames y.tmp to y.jpeg

Step 4b results in y.jpeg no longer being a link to x.jpeg.

This saving via a temp file is quite common in software that deals with potentially large files. There's a good reason for it - consider what happens if the software crashes part way through the saving process. If it did a straight overwrite of y.jpeg and crashed part way through, all you'd have is a corrupt image. But using the temp file, if it crashes during saving, you've at least still got your original version to go back to.

Anyway, answers to your questions:

  1. a.txt/b.txt is the expected result. However, you are misunderstanding what's going on underneath. The files are not being kept in sync. There is only one file! You've just given the one file two different names, so it can be accessed as a.txt or b.txt. Whichever one you edit, you're dealing with the same underlying data on the disk. If you have a 100MB file, and you create a thousand links for it, the data still only uses 100MB of your disk. (Well, maybe 101MB - the filesystem needs to use some space to keep track of file names.)
  2. Both - the contents of the file are irrelevant.
  3. Hard links only work on the same volume. This is roughly equivalent to Windows' notion of a "drive". It is possible (via RAID for example) to have a drive that spans multiple physical disks; and also possible (via partitions) to have multiple drives on the same physical disk. On Windows, hard links are only supported on NTFS volumes.

(ObPedantry: before anyone points it out, obviously when I say that hard links are not often used, I am ignoring the fact that the "original name" of the file is itself technically a hardlink. And that because directories have hardlinks to their parents and themselves, most directories end up with multiple hard links pointing to them.)


In reply to Re: about link() by tobyink
in thread about link() by exilepanda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.