25
25
html_root_url = "http://doc.rust-lang.org/glob/" ) ]
26
26
#![ cfg_attr( test, deny( warnings) ) ]
27
27
#![ cfg_attr( all( test, windows) , feature( std_misc) ) ]
28
- #![ feature( path, io, core, collections, unicode, fs , os ) ]
28
+ #![ feature( path, io, core, collections, unicode) ]
29
29
30
30
use std:: ascii:: AsciiExt ;
31
31
use std:: cell:: Cell ;
@@ -228,6 +228,10 @@ impl fmt::Display for GlobError {
228
228
}
229
229
}
230
230
231
+ fn is_dir ( p : & Path ) -> bool {
232
+ fs:: metadata ( p) . map ( |m| m. is_dir ( ) ) == Ok ( true )
233
+ }
234
+
231
235
/// An alias for a glob iteration result.
232
236
///
233
237
/// This represents either a matched path or a glob iteration error,
@@ -265,7 +269,7 @@ impl Iterator for Paths {
265
269
// idx -1: was already checked by fill_todo, maybe path was '.' or
266
270
// '..' that we can't match here because of normalization.
267
271
if idx == -1 as usize {
268
- if self . require_dir && !path . is_dir ( ) { continue ; }
272
+ if self . require_dir && !is_dir ( & path ) { continue ; }
269
273
return Some ( Ok ( path) ) ;
270
274
}
271
275
@@ -279,7 +283,7 @@ impl Iterator for Paths {
279
283
}
280
284
281
285
// the path is a directory, so it's a match
282
- if path . is_dir ( ) {
286
+ if is_dir ( & path ) {
283
287
// push this directory's contents
284
288
fill_todo ( & mut self . todo , self . dir_patterns . as_slice ( ) ,
285
289
next, & path, & self . options ) ;
@@ -316,7 +320,7 @@ impl Iterator for Paths {
316
320
// *AND* its children so we don't need to check the
317
321
// children
318
322
319
- if !self . require_dir || path . is_dir ( ) {
323
+ if !self . require_dir || is_dir ( & path ) {
320
324
return Some ( Ok ( path) ) ;
321
325
}
322
326
} else {
@@ -727,7 +731,7 @@ fn fill_todo(todo: &mut Vec<Result<(PathBuf, usize), GlobError>>,
727
731
} ;
728
732
729
733
let pattern = & patterns[ idx] ;
730
- let is_dir = path . is_dir ( ) ;
734
+ let is_dir = is_dir ( path ) ;
731
735
let curdir = path == Path :: new ( "." ) ;
732
736
match pattern_as_str ( pattern) {
733
737
Some ( s) => {
@@ -738,7 +742,7 @@ fn fill_todo(todo: &mut Vec<Result<(PathBuf, usize), GlobError>>,
738
742
// right away.
739
743
let special = "." == s. as_slice ( ) || ".." == s. as_slice ( ) ;
740
744
let next_path = if curdir { PathBuf :: new ( & s) } else { path. join ( & s) } ;
741
- if ( special && is_dir) || ( !special && next_path. exists ( ) ) {
745
+ if ( special && is_dir) || ( !special && fs :: metadata ( & next_path) . is_ok ( ) ) {
742
746
add ( todo, next_path) ;
743
747
}
744
748
} ,
0 commit comments