Skip to content

Commit 7273358

Browse files
committed
Support DirEntry metadata calls in miri
Signed-off-by: Alex Saveau <[email protected]>
1 parent 8147e6e commit 7273358

File tree

2 files changed

+16
-2
lines changed
  • library/std/src/sys/unix
  • src/tools/miri/tests/pass-dep/shims

2 files changed

+16
-2
lines changed

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,10 @@ impl DirEntry {
674674
self.file_name_os_str().to_os_string()
675675
}
676676

677-
#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "android"))]
677+
#[cfg(all(
678+
any(target_os = "linux", target_os = "emscripten", target_os = "android"),
679+
not(miri)
680+
))]
678681
pub fn metadata(&self) -> io::Result<FileAttr> {
679682
let fd = cvt(unsafe { dirfd(self.dir.dirp.0) })?;
680683
let name = self.name_cstr().as_ptr();
@@ -695,7 +698,10 @@ impl DirEntry {
695698
Ok(FileAttr::from_stat64(stat))
696699
}
697700

698-
#[cfg(not(any(target_os = "linux", target_os = "emscripten", target_os = "android")))]
701+
#[cfg(any(
702+
not(any(target_os = "linux", target_os = "emscripten", target_os = "android")),
703+
miri
704+
))]
699705
pub fn metadata(&self) -> io::Result<FileAttr> {
700706
lstat(&self.path())
701707
}

src/tools/miri/tests/pass-dep/shims/fs.rs

+8
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,14 @@ fn test_directory() {
404404
let mut file_names = dir_iter.map(|e| e.unwrap().file_name()).collect::<Vec<_>>();
405405
file_names.sort_unstable();
406406
assert_eq!(file_names, vec!["test_file_1", "test_file_2"]);
407+
// Test that read_dir metadata calls succeed
408+
assert_eq!(
409+
&[true, true],
410+
&*read_dir(&dir_path)
411+
.unwrap()
412+
.map(|e| e.unwrap().metadata().unwrap().is_file())
413+
.collect::<Vec<_>>()
414+
);
407415
// Deleting the directory should fail, since it is not empty.
408416
assert_eq!(ErrorKind::DirectoryNotEmpty, remove_dir(&dir_path).unwrap_err().kind());
409417
// Clean up the files in the directory

0 commit comments

Comments
 (0)