-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[fs] Path::new(r#"C:\hiberfil.sys"#).exists() returns false, despite the file existing #96980
Comments
Documentation explicitly documents that |
@nagisa true, the question was whether
(I'll note that this documentation is now wrong, since it now uses This would mean that the
but otherwise it'd be complete (although for reparse points, we'd still have to open the file). We could additionally do |
Hm, changing
|
@ChrisDenton given that it's reading the directory, it should make performance better (assuming one doesn't do the double call thing). I'm personally not that invested, I just thought I'd share with y'all since I have to fix this bug for the STL 😛 |
It's great that we have this report! I just want to make sure we investigate fully before making changes that may affect users of the standard library. I'll also note we do have the unstable std::fs::try_exists whose behaviour can change. |
Ok I tested with two users. For the sake of this example, I'll call them "Admin" and "User". As Admin I created a directory and denied User all access. Within the directory I then created a "test.txt" file and granted User access to just that file. As User, I tried using Thus |
FYI, Nushell has run into this in the wild: nushell/nushell#4975 We'll work around it by falling back to |
To be clear, using FindFirstFile as a fallback (rather than replacement) answers my concerns and I think would be the best solution to this issue. |
Windows: Use `FindFirstFileW` for getting the metadata of locked system files Fixes rust-lang#96980 Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory. Note that the test is a bit iffy. I don't know if `hiberfil.sys` actually exists in the CI. r? rust-lang/libs
Windows: Use `FindFirstFileW` for getting the metadata of locked system files Fixes rust-lang#96980 Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory. Note that the test is a bit iffy. I don't know if `hiberfil.sys` actually exists in the CI. r? rust-lang/libs
Windows: Use `FindFirstFileW` for getting the metadata of locked system files Fixes rust-lang#96980 Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory. Note that the test is a bit iffy. I don't know if `hiberfil.sys` actually exists in the CI. r? rust-lang/libs
I noticed this bug while researching the same bug in https://github.com/microsoft/STL.
Given
test.exe C:\hiberfil.sys
, I expected:Instead, this happened:
Solution
The related issue in the STL is microsoft/STL#2370; the PR to fix this in the STL is microsoft/STL#2715.
The problem is that
fs::metadata
opens the file; this is not allowed for the following four files (not sure if there are additional files which act similarly):C:\DumpStack.log.tmp
C:\hiberfil.sys
C:\pagefile.sys
C:\swapfile.sys
We can get around this by using
FindFirstFileW
instead ofopen()
; is that something that's desired, or is this considered a weird enough use case that we aren't interested in fixing it?The text was updated successfully, but these errors were encountered: