Skip to content

Commit 63b633e

Browse files
committed
Let the get_files function skip excluded directories
1 parent edeab18 commit 63b633e

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

utils/src/lib.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,21 @@ pub struct FileEntry {
1414

1515
#[cfg_attr(all(debug_assertions, not(feature = "debug-embed")), allow(unused))]
1616
pub fn get_files(folder_path: String, matcher: PathMatcher) -> impl Iterator<Item = FileEntry> {
17+
let temp_folder_path = folder_path.clone();
18+
1719
walkdir::WalkDir::new(&folder_path)
1820
.follow_links(true)
1921
.sort_by_file_name()
2022
.into_iter()
23+
.filter_entry(move |e|{
24+
let rel_path = path_to_str(e.path().strip_prefix(&temp_folder_path).unwrap());
25+
if e.file_type().is_dir() {
26+
// dir must be explicitly excluded
27+
!matcher.is_path_excluded(&rel_path)
28+
} else{
29+
matcher.is_path_included(&rel_path)
30+
}
31+
})
2132
.filter_map(|e| e.ok())
2233
.filter(|e| e.file_type().is_file())
2334
.filter_map(move |e| {
@@ -29,11 +40,7 @@ pub fn get_files(folder_path: String, matcher: PathMatcher) -> impl Iterator<Ite
2940
} else {
3041
rel_path
3142
};
32-
if matcher.is_path_included(&rel_path) {
33-
Some(FileEntry { rel_path, full_canonical_path })
34-
} else {
35-
None
36-
}
43+
Some(FileEntry { rel_path, full_canonical_path })
3744
})
3845
}
3946

@@ -172,6 +179,9 @@ impl PathMatcher {
172179
pub fn is_path_included(&self, path: &str) -> bool {
173180
!self.exclude_matcher.is_match(path) && (self.include_matcher.is_empty() || self.include_matcher.is_match(path))
174181
}
182+
pub fn is_path_excluded(&self, path: &str) -> bool {
183+
self.exclude_matcher.is_match(path)
184+
}
175185
}
176186

177187
#[cfg(not(feature = "include-exclude"))]
@@ -182,4 +192,7 @@ impl PathMatcher {
182192
pub fn is_path_included(&self, _path: &str) -> bool {
183193
true
184194
}
195+
pub fn is_path_excluded(&self, _path: &str) -> bool {
196+
false
197+
}
185198
}

0 commit comments

Comments
 (0)