about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-01-31 07:00:44 +0100
committerGitHub <noreply@github.com>2022-01-31 07:00:44 +0100
commitcd27f1b56ed2efc51dda161da39cf1da853d6976 (patch)
tree24d0a38b1a7eeabb2e779929a89bceb386772e25
parentbc2c4feaeb43c14bd42709eb03615dfb48553950 (diff)
parentd70b9c03ec1b4abe2fa88f60934e7acdfccc7a87 (diff)
downloadrust-cd27f1b56ed2efc51dda161da39cf1da853d6976.tar.gz
rust-cd27f1b56ed2efc51dda161da39cf1da853d6976.zip
Rollup merge of #93471 - cuviper:direntry-file_type-stat, r=the8472
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 65e000d9215..878796065c8 100644
--- a/library/std/src/sys/unix/fs.rs
+++ b/library/std/src/sys/unix/fs.rs
@@ -598,7 +598,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(
@@ -616,7 +616,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()),
         }
     }