Skip to content

Commit 221c7c2

Browse files
committed
fallback to lstat when stat fails on Windows
1 parent cf79eec commit 221c7c2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

std/src/sys/windows/fs.rs

Lines changed: 13 additions & 1 deletion
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)