ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

keeping/saving cloned files

<< < (8/8)

mwang:
I do like hardlinks, IF they work. I reorganize my files and folders quite often, so softlinks/junctions break all the time. Unfortunately, hardlinks on NTFS just don't work as reliably as expected.

To be fair, I work mostly with text files on Linux, so I'm not sure if files created by Open Office, e.g., have the same problem as MS Office files on Windows.

Armando:
Hardlinks would be ideal for me if their behavior was consistent.
Unfortunately, because they don't always work, I've had to find other ways of achieving similar results.

I didn't have any trouble with hard links - I just never really warmed to them...
-Darwin (October 20, 2007, 08:04 AM)
--- End quote ---

Try them with word documents : you should have problems.

namsupo:
Hard links do work quite reliably on NTFS, the problem is the way Word is saving files.

All files are hard links. A filename in a directory is just a record in the file system of a bunch of data located somewhere on the disk. When you create a hard link to an existing file, all you are doing is creating another filename entry to the same block of data. The two entries are indistinguishable. There is literally no way to tell which one was the original and which one is the hard link.

The problem described above arises because of the way Word saves files. Instead of opening the existing file, clearing out its contents and then writing new data, Word does what is called a "safe save". That is, it write the new document to a temporary file first. Once the file has been safely written to disk, it deletes the original file, and renames the temporary file.

This causes a problem when you have two hard links pointing to the same chunk of data, as deleting one of the links does not delete the data. All it does is delete the duplicate filename record. It is only when the last hard link to a file is deleted that the actual data is removed.

So in the above scenario with Word, one of the hard links is deleted during the safe save process, but the other one is not (since Word doesn't know anything about it.) Word then renames its temporary file back to the name of the original, but this is now a new filename record pointing to a new chunk of data. The remaining hard link to the old data is still present, still works, and still points to the old data.

I think it's reasons like this that explain why Microsoft draw such little attention to the linking abilities of NTFS - it's not that they don't work, it's just that they can easily cause confusion when you don't quite understand how it works.

Nudel:
I guess namsupo already covered most of this and his reply got in before mine, but here's mine anyway in case the little ASCII diagrams are helpful. :-)


Hardlinks would be ideal for me if their behavior was consistent.
Unfortunately, because they don't always work, I've had to find other ways of achieving similar results.-Armando (October 21, 2007, 01:57 AM)
--- End quote ---
Their behaviour is consistent. If it wasn't it would be very worrying for a filesystem feature! :-)

What isn't consistent is how you (indirectly, via the programs you use on your files) are interacting with the hardlinked files. A hardlink to a file is simply an additional filename which points to the same data that the original filename pointed to.

When you create a file normally you are, without knowing it, effectively creating a hardlink which associates a filename with some data (the file contents):

FilenameA -> [Data1]

If you then create a hardlink you will have two names both pointing to the same data:

FilenameA -> [Data1] <- FilenameB

Hardlinks point to data and not to filenames! FilenameB is pointing to the same data as FilenameA but it is not actually pointing to FilenameA. (That would be a symbolic link.) If the meaning of FilenameA changes it has no effect whatsoever on FilenameB.

If you delete FilenameA but leave FilenameB then you're left with this:

FilenameB -> [Data1]

If you now create a new file and happen to call it FilenameA then it's a completely separate file. There is no connection at all between FilenameA and FilenameB:

FilenameA -> [Data2]
FilenameB -> [Data1]

So when Word deletes the old file and then saves a new file with the same name that's what happens. If Word instead overwrote the old data with the new data, without deleting or creating any files, then the problem would not occur.

Of course, you often cannot change how a program saves its files. (Sometimes you can, sometimes it's out of your hands.) So using links like this isn't a good idea and can lead to confusion. Links in general can lead to confusion and shouldn't be used gratuitously. (Symbolic links and shortcut files are less of an issue). But while I recommend that people don't use the things when it isn't necessary, the way hardlinks work is completely consistent and well-defined.

Navigation

[0] Message Index

[*] Previous page

Go to full version