From 2dbda0af15f95c5e816f9357c59fad3576e1a45a Mon Sep 17 00:00:00 2001 From: NagaChaitanya Vellanki Date: Thu, 16 Mar 2023 15:08:14 -0700 Subject: [PATCH] fallback to lstat when stat fails on Windows --- library/std/src/sys/windows/fs.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index d2c597664fa..a4161c1c3c4 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -1236,7 +1236,19 @@ pub fn link(_original: &Path, _link: &Path) -> io::Result<()> { } pub fn stat(path: &Path) -> io::Result { - 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 {