From 2dbda0af15f95c5e816f9357c59fad3576e1a45a Mon Sep 17 00:00:00 2001 From: NagaChaitanya Vellanki Date: Thu, 16 Mar 2023 15:08:14 -0700 Subject: [PATCH 1/3] 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 d2c597664fa78..a4161c1c3c4c2 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 { From 0aad0b32ae05d7d03d0c18c7083edf02c7e3f857 Mon Sep 17 00:00:00 2001 From: NagaChaitanya Vellanki Date: Thu, 16 Mar 2023 17:07:41 -0700 Subject: [PATCH 2/3] run rustfmt on changes --- library/std/src/sys/windows/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index a4161c1c3c4c2..ef8f73645be79 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -1246,7 +1246,7 @@ pub fn stat(path: &Path) -> io::Result { } } Err(err) - }, + } Ok(attrs) => Ok(attrs), } } From 32c589b2363eb96649e5692b4b335777dbeb2f9d Mon Sep 17 00:00:00 2001 From: NagaChaitanya Vellanki Date: Fri, 17 Mar 2023 10:44:22 -0700 Subject: [PATCH 3/3] Modify code style as per comments --- library/std/src/sys/windows/fs.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index ef8f73645be79..373157bd9e836 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -1237,17 +1237,15 @@ pub fn link(_original: &Path, _link: &Path) -> io::Result<()> { pub fn stat(path: &Path) -> io::Result { 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) 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), + result => result, } }