Skip to content

Commit d70b9c0

Browse files
committed
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`.
1 parent a00e130 commit d70b9c0

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
@@ -590,7 +590,7 @@ impl DirEntry {
590590
target_os = "vxworks"
591591
))]
592592
pub fn file_type(&self) -> io::Result<FileType> {
593-
lstat(&self.path()).map(|m| m.file_type())
593+
self.metadata().map(|m| m.file_type())
594594
}
595595

596596
#[cfg(not(any(
@@ -608,7 +608,7 @@ impl DirEntry {
608608
libc::DT_SOCK => Ok(FileType { mode: libc::S_IFSOCK }),
609609
libc::DT_DIR => Ok(FileType { mode: libc::S_IFDIR }),
610610
libc::DT_BLK => Ok(FileType { mode: libc::S_IFBLK }),
611-
_ => lstat(&self.path()).map(|m| m.file_type()),
611+
_ => self.metadata().map(|m| m.file_type()),
612612
}
613613
}
614614

0 commit comments

Comments
 (0)