fix std.file.exists and std.file.DirEntry Windows version for system locked files and Windows root paths
text/plain
5301
Comments
Comment #0 by vital.fadeev — 2020-10-04T06:53:46Z
Created attachment 1805
file
"File does not exist" FileException on existent file: c:\hiberfil.sys
Source code:
import std.stdio;
void main()
{
import std.file : DirEntry;
writeln( DirEntry( "c:\\hiberfil.sys" ).isDir() );
}
I expected "false".
Not FileException.
Because "c:\\hiberfil.sys" is exist.
Comment #1 by vital.fadeev — 2020-10-04T07:30:13Z
I look into the std.file... function "existsImpl()"...
...
version (Windows)
{
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
// fileio/base/getfileattributes.asp
return GetFileAttributesW(namez) != 0xFFFFFFFF; // INVALID_FILE_ATTRIBUTES
}
...
existsImpl() functions return "false" on file "c:\\hiberfil.sys".
Because INVALID_FILE_ATTRIBUTES.
It not correct? because file exists.
I tried several ways: GetFileAttributesW(), GetFileAttributesExW(), FindFirstFileW().
Working solution :
WIN32_FIND_DATAW fd;
auto hFind = FindFirstFile ( "c:\\hiberfil.sys", &fd );
if ( hFind != INVALID_HANDLE_VALUE )
{
writeln( "[ OK ]" );
FindClose( hFind );
}
Of course solution above is a little slower than GetFileAttributes(), but work correct with .sys files.
I will suggest using "FindFirstFileW()" in the "std.file: existsImpl()" there is no better solution yet.
Comment #2 by vital.fadeev — 2020-10-04T15:19:55Z
Created attachment 1806
std-file-dirEnrty-windows.patch
Comment #3 by vital.fadeev — 2020-10-04T15:20:06Z
I fix bug.
Check the patch.
I will be happy when it will be committed in next version.
std-file-dirEnrty-windows.patch
( see attached .patch in ticket )
Comment #4 by vital.fadeev — 2020-10-04T15:22:59Z
FindFirstFileW() can read attributes of system locked files.
I used it.
Comment #5 by vital.fadeev — 2020-10-04T15:28:53Z
Created attachment 1807
fixed std.file.exists()
Using FindFirstFile() for check file existens under Windows.
Because correct work with system locked files: like a c:\hiberfil.sys
Comment #6 by vital.fadeev — 2020-10-05T12:29:36Z
Created attachment 1808
fix std.file.exists and std.file.DirEntry Windows version for system locked files and Windows root paths
Latest version patch. Includes all previous patches.
fix:
- std.file.exists
- std.file.DirEntry Windows version for system locked files
- Windows root paths attributes
Comment #7 by robert.schadek — 2024-12-01T16:37:45Z