Skip to content

Commit cd27f1b

Browse files
authored
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`.
2 parents bc2c4fe + d70b9c0 commit cd27f1b

File tree

1 file changed

+2
-2
lines changed
  • library/std/src/sys/unix

1 file changed

+2
-2
lines changed

library/std/src/sys/unix/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ impl DirEntry {
598598
target_os = "vxworks"
599599
))]
600600
pub fn file_type(&self) -> io::Result<FileType> {
601-
lstat(&self.path()).map(|m| m.file_type())
601+
self.metadata().map(|m| m.file_type())
602602
}
603603

604604
#[cfg(not(any(
@@ -616,7 +616,7 @@ impl DirEntry {
616616
libc::DT_SOCK => Ok(FileType { mode: libc::S_IFSOCK }),
617617
libc::DT_DIR => Ok(FileType { mode: libc::S_IFDIR }),
618618
libc::DT_BLK => Ok(FileType { mode: libc::S_IFBLK }),
619-
_ => lstat(&self.path()).map(|m| m.file_type()),
619+
_ => self.metadata().map(|m| m.file_type()),
620620
}
621621
}
622622

0 commit comments

Comments
 (0)