about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2022-01-29 16:58:18 -0800
committerJosh Stone <jistone@redhat.com>2022-01-29 16:58:18 -0800
commitd70b9c03ec1b4abe2fa88f60934e7acdfccc7a87 (patch)
tree89b08f13449cd98b19a99842ec887014258353ff
parenta00e130dae74a213338e2b095ec855156d8f3d8a (diff)
downloadrust-d70b9c03ec1b4abe2fa88f60934e7acdfccc7a87.tar.gz
rust-d70b9c03ec1b4abe2fa88f60934e7acdfccc7a87.zip
unix: Use metadata for `DirEntry::file_type` fallback
When `DirEntry::file_type` fails to match a known `d_type`, we should
fall back to `DirEntry::metadata` instead of a bare `lstat`, because
this is faster and more reliable on targets with `fstatat`.
-rw-r--r--library/std/src/sys/unix/fs.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs
index 5b2199c2b7f..fb7a356ca28 100644
--- a/library/std/src/sys/unix/fs.rs
+++ b/library/std/src/sys/unix/fs.rs
@@ -590,7 +590,7 @@ impl DirEntry {
         target_os = "vxworks"
     ))]
     pub fn file_type(&self) -> io::Result<FileType> {
-        lstat(&self.path()).map(|m| m.file_type())
+        self.metadata().map(|m| m.file_type())
     }
 
     #[cfg(not(any(
@@ -608,7 +608,7 @@ impl DirEntry {
             libc::DT_SOCK => Ok(FileType { mode: libc::S_IFSOCK }),
             libc::DT_DIR => Ok(FileType { mode: libc::S_IFDIR }),
             libc::DT_BLK => Ok(FileType { mode: libc::S_IFBLK }),
-            _ => lstat(&self.path()).map(|m| m.file_type()),
+            _ => self.metadata().map(|m| m.file_type()),
         }
     }