Skip to content

Commit 2a3c0e3

Browse files
authored
Rollup merge of #109235 - chaitanyav:master, r=ChrisDenton
fallback to lstat when stat fails on Windows Fixes #109106 ````@ChrisDenton```` please let me know if this is the expected behavior for stat on windows
2 parents dfd2b64 + 32c589b commit 2a3c0e3

File tree

1 file changed

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

1 file changed

+11
-1
lines changed

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,17 @@ pub fn link(_original: &Path, _link: &Path) -> io::Result<()> {
12361236
}
12371237

12381238
pub fn stat(path: &Path) -> io::Result<FileAttr> {
1239-
metadata(path, ReparsePoint::Follow)
1239+
match metadata(path, ReparsePoint::Follow) {
1240+
Err(err) if err.raw_os_error() == Some(c::ERROR_CANT_ACCESS_FILE as i32) => {
1241+
if let Ok(attrs) = lstat(path) {
1242+
if !attrs.file_type().is_symlink() {
1243+
return Ok(attrs);
1244+
}
1245+
}
1246+
Err(err)
1247+
}
1248+
result => result,
1249+
}
12401250
}
12411251

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

0 commit comments

Comments
 (0)