Skip to content

Commit

Permalink
Rollup merge of rust-lang#109235 - chaitanyav:master, r=ChrisDenton
Browse files Browse the repository at this point in the history
fallback to lstat when stat fails on Windows

Fixes rust-lang#109106
`@ChrisDenton` please let me know if this is the expected behavior for stat on windows
  • Loading branch information
matthiaskrgr authored Mar 17, 2023
2 parents f369855 + 32c589b commit 23cbfd4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion library/std/src/sys/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,17 @@ pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
}

pub fn stat(path: &Path) -> io::Result<FileAttr> {
metadata(path, ReparsePoint::Follow)
match metadata(path, ReparsePoint::Follow) {
Err(err) if err.raw_os_error() == Some(c::ERROR_CANT_ACCESS_FILE as i32) => {
if let Ok(attrs) = lstat(path) {
if !attrs.file_type().is_symlink() {
return Ok(attrs);
}
}
Err(err)
}
result => result,
}
}

pub fn lstat(path: &Path) -> io::Result<FileAttr> {
Expand Down

0 comments on commit 23cbfd4

Please sign in to comment.