@@ -43,6 +43,7 @@ use std::path::is_sep;
4343pub struct Paths {
4444 root : Path ,
4545 dir_patterns : Vec < Pattern > ,
46+ require_dir : bool ,
4647 options : MatchOptions ,
4748 todo : Vec < ( Path , uint ) > ,
4849}
@@ -106,6 +107,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
106107 return Paths {
107108 root : root,
108109 dir_patterns : Vec :: new ( ) ,
110+ require_dir : false ,
109111 options : options,
110112 todo : Vec :: new ( ) ,
111113 } ;
@@ -118,6 +120,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
118120 . split_terminator ( is_sep)
119121 . map ( |s| Pattern :: new ( s) )
120122 . collect :: < Vec < Pattern > > ( ) ;
123+ let require_dir = pattern. chars ( ) . next_back ( ) . map ( is_sep) == Some ( true ) ;
121124
122125 let mut todo = Vec :: new ( ) ;
123126 if dir_patterns. len ( ) > 0 {
@@ -130,6 +133,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
130133 Paths {
131134 root : root,
132135 dir_patterns : dir_patterns,
136+ require_dir : require_dir,
133137 options : options,
134138 todo : todo,
135139 }
@@ -146,7 +150,10 @@ impl Iterator<Path> for Paths {
146150 let ( path, idx) = self . todo . pop ( ) . unwrap ( ) ;
147151 // idx -1: was already checked by fill_todo, maybe path was '.' or
148152 // '..' 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+ }
150157 let ref pattern = * self . dir_patterns . get ( idx) ;
151158
152159 if pattern. matches_with ( match path. filename_str ( ) {
@@ -161,7 +168,10 @@ impl Iterator<Path> for Paths {
161168 if idx == self . dir_patterns . len ( ) - 1 {
162169 // it is not possible for a pattern to match a directory *AND* its children
163170 // 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+ }
165175 } else {
166176 fill_todo ( & mut self . todo , self . dir_patterns . as_slice ( ) ,
167177 idx + 1 , & path, self . options ) ;
0 commit comments