about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-03-18 00:05:53 +0100
committerGitHub <noreply@github.com>2023-03-18 00:05:53 +0100
commit2a3c0e34cb5616c336d8c3c4e14701b4df364e60 (patch)
tree6c10ea7db9f894ce9aa9f5a725ba9082e6867e15
parentdfd2b6493a4a9e44194faa11e4ae30f62d8a403b (diff)
parent32c589b2363eb96649e5692b4b335777dbeb2f9d (diff)
downloadrust-2a3c0e34cb5616c336d8c3c4e14701b4df364e60.tar.gz
rust-2a3c0e34cb5616c336d8c3c4e14701b4df364e60.zip
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
-rw-r--r--library/std/src/sys/windows/fs.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs
index d2c597664fa..373157bd9e8 100644
--- a/library/std/src/sys/windows/fs.rs
+++ b/library/std/src/sys/windows/fs.rs
@@ -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> {