diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-31 07:00:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-31 07:00:44 +0100 |
| commit | cd27f1b56ed2efc51dda161da39cf1da853d6976 (patch) | |
| tree | 24d0a38b1a7eeabb2e779929a89bceb386772e25 | |
| parent | bc2c4feaeb43c14bd42709eb03615dfb48553950 (diff) | |
| parent | d70b9c03ec1b4abe2fa88f60934e7acdfccc7a87 (diff) | |
| download | rust-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.rs | 4 |
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()), } } |
