Skip to content

Commit 2dbda0a

Browse files
committed
fallback to lstat when stat fails on Windows
1 parent 1203e08 commit 2dbda0a

File tree

1 file changed

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

1 file changed

+13
-1
lines changed

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,19 @@ 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) => {
1241+
if err.raw_os_error() == Some(c::ERROR_CANT_ACCESS_FILE as i32) {
1242+
if let Ok(attrs) = lstat(path) {
1243+
if !attrs.file_type().is_symlink() {
1244+
return Ok(attrs);
1245+
}
1246+
}
1247+
}
1248+
Err(err)
1249+
},
1250+
Ok(attrs) => Ok(attrs),
1251+
}
12401252
}
12411253

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

0 commit comments

Comments
 (0)