Skip to content

FileExists(Filename) returns FALSE on Windows Server if Shadow Copies are activated

Summary

FileExists(Filename) returns a False Negative (returns FALSE) if the OS (Windows Server) has created a Shadow Copy of the file in question.

This unexpected behavior can lead to self-inflicted data loss, for example if you use it as follows: if FileExists(DestFilename1) then Reset(File1) else Rewrite(File1);

System Information

Windows Server with activated VSS (Volume Shadow Copy Service) or any OS if a SymLink exists and the user is not allowed to access the resolved target path.

Steps to reproduce

On Windows Server, enable Shadow Copies for a volume and wait 3 days for the system to automatically replace files with shadow copies. From that point on, FileExists(Filename) will fail.

What is the current bug behavior?

FileExists(Filename) returns FALSE although the file is visible and accessible.

What is the expected (correct) behavior?

FileExists(Filename) should return TRUE on a file that is visible and accessible.

Possible fixes

Workaround: programmers can use FileExists(Filename,FALSE) instead.

Cause of the problem: Since the second parameter FollowLink default is true (this is also the case in Delphi), FileExists(Filename) always tries to follow a SymLink. After that, an additional check is made to see if the SymLink target exists. This second check fails for shadow copies because the Windows user has no permission to access the shadow copy system folder.

Possible fix: In Delphi it is solved in such a way that not the SymLink destination is traced, but the requested filename is opened for reading. This also works with shadow copies and returns TRUE as expected.

Edited by Jorg3000
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information