@@ -43,6 +43,7 @@ use std::path::is_sep;
43
43
pub struct Paths {
44
44
root : Path ,
45
45
dir_patterns : Vec < Pattern > ,
46
+ require_dir : bool ,
46
47
options : MatchOptions ,
47
48
todo : Vec < ( Path , uint ) > ,
48
49
}
@@ -106,6 +107,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
106
107
return Paths {
107
108
root : root,
108
109
dir_patterns : Vec :: new ( ) ,
110
+ require_dir : false ,
109
111
options : options,
110
112
todo : Vec :: new ( ) ,
111
113
} ;
@@ -118,6 +120,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
118
120
. split_terminator ( is_sep)
119
121
. map ( |s| Pattern :: new ( s) )
120
122
. collect :: < Vec < Pattern > > ( ) ;
123
+ let require_dir = pattern. chars ( ) . next_back ( ) . map ( is_sep) == Some ( true ) ;
121
124
122
125
let mut todo = Vec :: new ( ) ;
123
126
if dir_patterns. len ( ) > 0 {
@@ -130,6 +133,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
130
133
Paths {
131
134
root : root,
132
135
dir_patterns : dir_patterns,
136
+ require_dir : require_dir,
133
137
options : options,
134
138
todo : todo,
135
139
}
@@ -146,7 +150,10 @@ impl Iterator<Path> for Paths {
146
150
let ( path, idx) = self . todo . pop ( ) . unwrap ( ) ;
147
151
// idx -1: was already checked by fill_todo, maybe path was '.' or
148
152
// '..' that we can't match here because of normalization.
149
- if idx == -1 as uint { return Some ( path) ; }
153
+ if idx == -1 as uint {
154
+ if self . require_dir && !path. is_dir ( ) { continue ; }
155
+ return Some ( path) ;
156
+ }
150
157
let ref pattern = * self . dir_patterns . get ( idx) ;
151
158
152
159
if pattern. matches_with ( match path. filename_str ( ) {
@@ -161,7 +168,10 @@ impl Iterator<Path> for Paths {
161
168
if idx == self . dir_patterns . len ( ) - 1 {
162
169
// it is not possible for a pattern to match a directory *AND* its children
163
170
// so we don't need to check the children
164
- return Some ( path) ;
171
+
172
+ if !self . require_dir || path. is_dir ( ) {
173
+ return Some ( path) ;
174
+ }
165
175
} else {
166
176
fill_todo ( & mut self . todo , self . dir_patterns . as_slice ( ) ,
167
177
idx + 1 , & path, self . options ) ;
0 commit comments