未验证 提交 cd27f1b5 编写于 作者: M Matthias Krüger 提交者: GitHub

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`.
......@@ -598,7 +598,7 @@ pub fn metadata(&self) -> io::Result<FileAttr> {
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 @@ pub fn file_type(&self) -> io::Result<FileType> {
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()),
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册