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`.
This commit is contained in:
@@ -590,7 +590,7 @@ impl DirEntry {
|
|||||||
target_os = "vxworks"
|
target_os = "vxworks"
|
||||||
))]
|
))]
|
||||||
pub fn file_type(&self) -> io::Result<FileType> {
|
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(
|
#[cfg(not(any(
|
||||||
@@ -608,7 +608,7 @@ impl DirEntry {
|
|||||||
libc::DT_SOCK => Ok(FileType { mode: libc::S_IFSOCK }),
|
libc::DT_SOCK => Ok(FileType { mode: libc::S_IFSOCK }),
|
||||||
libc::DT_DIR => Ok(FileType { mode: libc::S_IFDIR }),
|
libc::DT_DIR => Ok(FileType { mode: libc::S_IFDIR }),
|
||||||
libc::DT_BLK => Ok(FileType { mode: libc::S_IFBLK }),
|
libc::DT_BLK => Ok(FileType { mode: libc::S_IFBLK }),
|
||||||
_ => lstat(&self.path()).map(|m| m.file_type()),
|
_ => self.metadata().map(|m| m.file_type()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user