MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / assert_empty_dir

Function assert_empty_dir

crates/test-programs/src/bin/p1_fd_readdir.rs:70–95  ·  view source on GitHub ↗
(dir_fd: wasip1::Fd)

Source from the content-addressed store, hash-verified

68}
69
70unsafe fn assert_empty_dir(dir_fd: wasip1::Fd) {
71 let stat = wasip1::fd_filestat_get(dir_fd).expect("failed filestat");
72
73 let (mut dirs, eof) = exec_fd_readdir(dir_fd, 0);
74 assert!(eof, "expected to read the entire directory");
75 dirs.sort_by_key(|d| d.name.clone());
76 assert_eq!(dirs.len(), 2, "expected two entries in an empty directory");
77 let mut dirs = dirs.into_iter();
78
79 // the first entry should be `.`
80 let dir = dirs.next().expect("first entry is None");
81 assert_eq!(dir.name, ".", "first name");
82 assert_eq!(dir.dirent.d_type, wasip1::FILETYPE_DIRECTORY, "first type");
83 assert_eq!(dir.dirent.d_ino, stat.ino);
84 assert_eq!(dir.dirent.d_namlen, 1);
85
86 // the second entry should be `..`
87 let dir = dirs.next().expect("second entry is None");
88 assert_eq!(dir.name, "..", "second name");
89 assert_eq!(dir.dirent.d_type, wasip1::FILETYPE_DIRECTORY, "second type");
90
91 assert!(
92 dirs.next().is_none(),
93 "the directory should be seen as empty"
94 );
95}
96
97unsafe fn test_fd_readdir(dir_fd: wasip1::Fd) {
98 // Check the behavior in an empty directory

Callers 1

test_fd_readdirFunction · 0.70

Calls 7

fd_filestat_getFunction · 0.85
exec_fd_readdirFunction · 0.85
sort_by_keyMethod · 0.80
expectMethod · 0.45
cloneMethod · 0.45
into_iterMethod · 0.45
nextMethod · 0.45

Tested by 1

test_fd_readdirFunction · 0.56