Skip to content

Commit

Permalink
fallback to lstat when stat fails on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyav committed Mar 16, 2023
1 parent 1203e08 commit 2dbda0a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 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,19 @@ 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)
},
Ok(attrs) => Ok(attrs),
}
}

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

0 comments on commit 2dbda0a

Please sign in to comment.