diff options
| author | NagaChaitanya Vellanki <pnagato@protonmail.com> | 2023-03-16 15:08:14 -0700 |
|---|---|---|
| committer | NagaChaitanya Vellanki <pnagato@protonmail.com> | 2023-03-16 16:57:55 -0700 |
| commit | 2dbda0af15f95c5e816f9357c59fad3576e1a45a (patch) | |
| tree | 10fdf0e7ae00a7159928ea3dcc6b5adde10b93ce /library/std/src/sys | |
| parent | 1203e0866e6c3659775efcb8aecad21dc13ef38b (diff) | |
| download | rust-2dbda0af15f95c5e816f9357c59fad3576e1a45a.tar.gz rust-2dbda0af15f95c5e816f9357c59fad3576e1a45a.zip | |
fallback to lstat when stat fails on Windows
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/windows/fs.rs | 14 |
1 files changed, 13 insertions, 1 deletions
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<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) + }, + Ok(attrs) => Ok(attrs), + } } pub fn lstat(path: &Path) -> io::Result<FileAttr> { |
