Thread overview
[Issue 21289] [The D Bug Tracker] "File does not exist" FileException on c:\hiberfil.sys
Oct 04, 2020
Vital
Oct 04, 2020
Vital
Oct 04, 2020
Vital
Oct 04, 2020
Vital
Oct 04, 2020
Vital
Oct 05, 2020
Vital
Oct 08, 2020
Vital
October 04, 2020
https://issues.dlang.org/show_bug.cgi?id=21289

--- Comment #1 from Vital <vital.fadeev@gmail.com> ---
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.

--
October 04, 2020
https://issues.dlang.org/show_bug.cgi?id=21289

--- Comment #2 from Vital <vital.fadeev@gmail.com> ---
Created attachment 1806
  --> https://issues.dlang.org/attachment.cgi?id=1806&action=edit
std-file-dirEnrty-windows.patch

--
October 04, 2020
https://issues.dlang.org/show_bug.cgi?id=21289

--- Comment #3 from Vital <vital.fadeev@gmail.com> ---
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 )

--
October 04, 2020
https://issues.dlang.org/show_bug.cgi?id=21289

--- Comment #4 from Vital <vital.fadeev@gmail.com> ---
FindFirstFileW() can read attributes of system locked files.
I used it.

--
October 04, 2020
https://issues.dlang.org/show_bug.cgi?id=21289

--- Comment #5 from Vital <vital.fadeev@gmail.com> ---
Created attachment 1807
  --> https://issues.dlang.org/attachment.cgi?id=1807&action=edit
fixed std.file.exists()

Using FindFirstFile() for check file existens under Windows.
Because correct work with system locked files: like a c:\hiberfil.sys

--
October 05, 2020
https://issues.dlang.org/show_bug.cgi?id=21289

--- Comment #6 from Vital <vital.fadeev@gmail.com> ---
Created attachment 1808
  --> https://issues.dlang.org/attachment.cgi?id=1808&action=edit
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

--
October 08, 2020
https://issues.dlang.org/show_bug.cgi?id=21289

Vital <vital.fadeev@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|dlang.org                   |phobos

--