diff options
| author | Chris Denton <christophersdenton@gmail.com> | 2022-07-05 09:13:40 +0100 |
|---|---|---|
| committer | Chris Denton <christophersdenton@gmail.com> | 2022-07-05 09:15:35 +0100 |
| commit | 8d4adad953edef2ef94b02e2bb1ed9b22bb1d975 (patch) | |
| tree | d0f78ce23e8d3a4301aa284e0396f4c4dec09f8a /library/std/src/fs | |
| parent | 13ab7962ac131733400356241c37e3ddd68d1aff (diff) | |
Windows: Use `FindFirstFileW` if `metadata` fails
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.
Diffstat (limited to 'library/std/src/fs')
| -rw-r--r-- | library/std/src/fs/tests.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index e8d0132f4b9..e1ebb1a690b 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -1534,3 +1534,14 @@ fn read_large_dir() { entry.unwrap(); } } + +#[test] +#[cfg(windows)] +fn hiberfil_sys() { + // Get the system drive, which is usually `C:`. + let mut hiberfil = crate::env::var("SystemDrive").unwrap(); + hiberfil.push_str(r"\hiberfil.sys"); + + fs::metadata(&hiberfil).unwrap(); + fs::symlink_metadata(&hiberfil).unwrap(); +} |
