Skip to content

Commit e2fd0c0

Browse files
Add read_dir_entries_recursive in run_make_support
1 parent 18d6200 commit e2fd0c0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/tools/run-make-support/src/path_helpers.rs

+15
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,18 @@ pub fn has_suffix<P: AsRef<Path>>(path: P, suffix: &str) -> bool {
8484
pub fn filename_contains<P: AsRef<Path>>(path: P, needle: &str) -> bool {
8585
path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(needle))
8686
}
87+
88+
/// Helper for reading entries in a given directory and its children.
89+
pub fn read_dir_entries_recursive<P: AsRef<Path>, F: FnMut(&Path)>(dir: P, mut callback: F) {
90+
fn read_dir_entries_recursive_inner<P: AsRef<Path>, F: FnMut(&Path)>(dir: P, callback: &mut F) {
91+
for entry in rfs::read_dir(dir) {
92+
let path = entry.unwrap().path();
93+
callback(&path);
94+
if path.is_dir() {
95+
read_dir_entries_recursive_inner(path, callback);
96+
}
97+
}
98+
}
99+
100+
read_dir_entries_recursive_inner(dir, &mut callback);
101+
}

0 commit comments

Comments
 (0)