@@ -14,10 +14,21 @@ pub struct FileEntry {
14
14
15
15
#[ cfg_attr( all( debug_assertions, not( feature = "debug-embed" ) ) , allow( unused) ) ]
16
16
pub fn get_files ( folder_path : String , matcher : PathMatcher ) -> impl Iterator < Item = FileEntry > {
17
+ let temp_folder_path = folder_path. clone ( ) ;
18
+
17
19
walkdir:: WalkDir :: new ( & folder_path)
18
20
. follow_links ( true )
19
21
. sort_by_file_name ( )
20
22
. 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
+ } )
21
32
. filter_map ( |e| e. ok ( ) )
22
33
. filter ( |e| e. file_type ( ) . is_file ( ) )
23
34
. filter_map ( move |e| {
@@ -29,11 +40,7 @@ pub fn get_files(folder_path: String, matcher: PathMatcher) -> impl Iterator<Ite
29
40
} else {
30
41
rel_path
31
42
} ;
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 } )
37
44
} )
38
45
}
39
46
@@ -172,6 +179,9 @@ impl PathMatcher {
172
179
pub fn is_path_included ( & self , path : & str ) -> bool {
173
180
!self . exclude_matcher . is_match ( path) && ( self . include_matcher . is_empty ( ) || self . include_matcher . is_match ( path) )
174
181
}
182
+ pub fn is_path_excluded ( & self , path : & str ) -> bool {
183
+ self . exclude_matcher . is_match ( path)
184
+ }
175
185
}
176
186
177
187
#[ cfg( not( feature = "include-exclude" ) ) ]
@@ -182,4 +192,7 @@ impl PathMatcher {
182
192
pub fn is_path_included ( & self , _path : & str ) -> bool {
183
193
true
184
194
}
195
+ pub fn is_path_excluded ( & self , _path : & str ) -> bool {
196
+ false
197
+ }
185
198
}
0 commit comments