Closed
Description
I noticed this bug while researching the same bug in https://github.com/microsoft/STL.
// test.rs
use std::{env, fs};
use std::path::Path;
fn main() {
for p in env::args().skip(1) {
println!("{:?}.exists() = {}", p, Path::new(p).exists());
println!(" => (metadata = {})", if fs::metadata(p).is_err() { "error" } else { "ok" });
}
}
Given test.exe C:\hiberfil.sys
, I expected:
"C:\\hiberfil.sys".exists() = true
=> (metadata = ok)
Instead, this happened:
"C:\\hiberfil.sys".exists() = false
=> (metadata = error)
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 of open()
; is that something that's desired, or is this considered a weird enough use case that we aren't interested in fixing it?