NTFS hard links (& ADS... and the Microsoft mess)

General questions about using ExamDiff Pro, ideas for new features, bug reports, and usage tips.
Post Reply
MSpagni
Expert Member
Posts: 642
Joined: Mon Mar 30, 2009 12:53 am
Location: Italy

NTFS hard links (& ADS... and the Microsoft mess)

Post by MSpagni »

Many programs destroy hard links and file comments when writing changes to a file.
The ExamDiff editor too.

Text editors written with microsoft's MFC most probably save documents using the little known CMirrorFile class which, instead of saving straight to the target filename, it creates a temporary file, writes in it, deletes the original and then renames the temporary to the actual filename.
As you can imagine, any stream or hard link information in the original file is lost.
WordPad and visual studio 6 are two known culprits.

Hard links are ok if you use straight CreateFile calls without mirror files, but that ruines ADS when overwriting existing files with comments.
The problem is with the dwCreationDisposition argument used with CreateFile API.
You can use for convenience CREATE_ALWAYS that doesn't care whether the file being written exists or not, but nukes the old file in case it does exist, including any parallel streams - thus destroying the summary information stream.

The message is: do not use CREATE_ALWAYS!
A little extra effort is required to examine if the file we are about to write exists or not. If it does, then use TRUNCATE_EXISTING which will preserve ADS. If it doesn't, then pass CREATE_NEW as the disposition parameter.
User avatar
psguru
Site Admin
Posts: 2396
Joined: Sat May 15, 2004 4:23 pm
Location: California
Contact:

Re: NTFS hard links (& ADS... and the Microsoft mess)

Post by psguru »

Did you try the "Overwrite files directly during saving" option under Options | File Editing? Using it will force EDPro to not create a temp file while saving.
psguru
PrestoSoft
MSpagni
Expert Member
Posts: 642
Joined: Mon Mar 30, 2009 12:53 am
Location: Italy

Re: NTFS hard links (& ADS... and the Microsoft mess)

Post by MSpagni »

Good point! It works.
Thank you.
Post Reply