-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[filesystem] Don't error on weird system files #2715
Conversation
This changes from using GetFileAttributesExW to FindFirstFileW, since FindFirstFileW gets the information from the directory and thus doesn't error out. Fixes microsoft#2370 This will require serious testing to make sure the behavior is the same.
given the following program: ```cxx #include <filesystem> #include <stdio.h> namespace fs = std::filesystem; int wmain(int argc, wchar_t **argv) { std::error_code ec; for (int i = 1; i < argc; ++i) { wprintf(L"exists(%ls): %ls\n", argv[i], fs::exists(argv[i], ec) ? L"true" : L"false"); if (ec) { wprintf(L" error: 0x%lX\n", ec.value()); } } } ``` before this change, the result of this program would be: ``` PS C:\..\nimazzuc\projects\stl-tests> .\exists.exe \\?\C:\hiberfil.sys exists(\??\C:\hiberfil.sys): false ``` after this change, ``` PS C:\..\nimazzuc\projects\stl-tests> .\exists.exe \\?\C:\hiberfil.sys exists(\\?\C:\hiberfil.sys): true ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one more round of comments and I think this will be ready to go!
I didn't test anything but I just had read a comment from the Rust issue:
rust-lang/rust#96980 (comment) so I decided to copy the comment for those who didn't follow the link |
While I think the two user scenario is more realistic, you can get the same outcome by simply denying yourself list folder permissions on the file's parent directory. This is simpler to test. |
this fixes the obvious bug of `FindFirstFileW(directory-we-dont-have-access-to/file-we-do)` that I didn't notice when implementing. This instead GetFileAttributesExW, followed by FindFirstFileW if that fails with ERROR_SHARING_VIOLATION. The change: Let testdir be a directory where the current user doesn't have list permissions; let testdir/testfile.txt be a file which the current user _does_ have permissions on. Then, FindFirstFileW(L"testdir/testfile.txt") will result in ERROR_ACCESS_DENIED, but GetFileAttributesExW(L"testdir/testfile.txt") will succeed.
@strega-nil-ms I pushed a conflict-free merge with
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for investigating and fixing this bug affecting 🐞 🔍 🐻 |
Co-authored-by: nicole mazzuca <mazzucan@outlook.com> Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
This changes from using GetFileAttributesExW to FindFirstFileW,
since FindFirstFileW gets the information from the directory
and thus doesn't error out.
Fixes #2370
This will require serious testing to make sure the behavior is the same.
Related issue in Rust: rust-lang/rust#96980