Page 1 of 1

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

Posted: Mon Dec 05, 2011 5:33 am
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.

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

Posted: Mon Dec 05, 2011 7:21 pm
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.

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

Posted: Tue Dec 06, 2011 11:43 pm
by MSpagni
Good point! It works.
Thank you.