Skip to content

Commit 56193b0

Browse files
authored
Rollup merge of rust-lang#107985 - alesito85:master, r=ChrisDenton
Added another error to be processed in fallback This pull request addresses the problem of Rust not being able to read file/directory metadata because the current user doesn't have permission to read the file and are thus inaccessible. One particular example is `System Volume Information`. But any example can be made by having a file/directory, which the current user can't access even though the system does allow to view the metadata, which is handled by the fallback. The fallback exists to get the metadata but it was limited to one error type. Having added ERROR_ACCESS_DENIED per Chris Denton's suggestion, file/directory properties are now properly read. Solution suggested by Chris Denton nushell/nushell#6857 (comment)
2 parents 5915309 + f72eb47 commit 56193b0

File tree

1 file changed

+6
-1
lines changed
  • library/std/src/sys/windows

1 file changed

+6
-1
lines changed

library/std/src/sys/windows/fs.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,12 @@ fn metadata(path: &Path, reparse: ReparsePoint) -> io::Result<FileAttr> {
12661266
// If the fallback fails for any reason we return the original error.
12671267
match File::open(path, &opts) {
12681268
Ok(file) => file.file_attr(),
1269-
Err(e) if e.raw_os_error() == Some(c::ERROR_SHARING_VIOLATION as _) => {
1269+
Err(e)
1270+
if [Some(c::ERROR_SHARING_VIOLATION as _), Some(c::ERROR_ACCESS_DENIED as _)]
1271+
.contains(&e.raw_os_error()) =>
1272+
{
1273+
// `ERROR_ACCESS_DENIED` is returned when the user doesn't have permission for the resource.
1274+
// One such example is `System Volume Information` as default but can be created as well
12701275
// `ERROR_SHARING_VIOLATION` will almost never be returned.
12711276
// Usually if a file is locked you can still read some metadata.
12721277
// However, there are special system files, such as

0 commit comments

Comments
 (0)