@@ -59,6 +59,7 @@ impl Search {
59
59
/// * `ignore_case` - Whether to ignore case or not
60
60
/// * `hidden` - Whether to search hidden files or not
61
61
/// * `filters` - Vector of filters to search by `DirEntry` data
62
+ /// * `dirs` - Whether to apply filters to directories and include them in results.
62
63
#[ allow( clippy:: too_many_arguments) ]
63
64
pub ( crate ) fn new (
64
65
search_location : impl AsRef < Path > ,
@@ -71,6 +72,7 @@ impl Search {
71
72
ignore_case : bool ,
72
73
with_hidden : bool ,
73
74
filters : Vec < FilterType > ,
75
+ dirs : bool ,
74
76
) -> Self {
75
77
let regex_search_input =
76
78
utils:: build_regex_search_input ( search_input, file_ext, strict, ignore_case) ;
@@ -85,7 +87,7 @@ impl Search {
85
87
86
88
// filters getting applied to walker
87
89
// only if all filters are true then the walker will return the file
88
- walker. filter_entry ( move |dir | filters. iter ( ) . all ( |f| f. apply ( dir ) ) ) ;
90
+ walker. filter_entry ( move |entry | filters. iter ( ) . all ( |f| f. apply ( entry , dirs ) ) ) ;
89
91
90
92
if let Some ( locations) = more_locations {
91
93
for location in locations {
@@ -101,6 +103,16 @@ impl Search {
101
103
102
104
Box :: new ( move |path_entry| {
103
105
if let Ok ( entry) = path_entry {
106
+ if !dirs {
107
+ // if dirs is false and entry is a directory,
108
+ // proceed with the search without sending its path or incrementing the counter
109
+ if let Ok ( m) = entry. metadata ( ) {
110
+ if m. file_type ( ) . is_dir ( ) {
111
+ return WalkState :: Continue ;
112
+ }
113
+ }
114
+ }
115
+
104
116
let path = entry. path ( ) ;
105
117
if let Some ( file_name) = path. file_name ( ) {
106
118
// Lossy means that if the file name is not valid UTF-8
0 commit comments