Skip to content

Commit 597ebc6

Browse files
committed
Merge pull request #30 from huonw/file-dir-wildcards
Ignore files for globs in patterns like */*
2 parents df456fd + 816f712 commit 597ebc6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2424
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2525
html_root_url = "http://doc.rust-lang.org/glob/")]
26-
#![allow(unstable)]
2726
#![cfg_attr(test, deny(warnings))]
27+
#![cfg_attr(test, feature(os))]
28+
#![feature(path, io, core, collections, hash, std_misc, unicode)]
2829

2930
use std::ascii::AsciiExt;
3031
use std::cell::Cell;
@@ -705,7 +706,7 @@ fn fill_todo(todo: &mut Vec<Result<(Path, usize), GlobError>>, patterns: &[Patte
705706
};
706707

707708
let pattern = &patterns[idx];
708-
709+
let is_dir = path.is_dir();
709710
match pattern_as_str(pattern) {
710711
Some(s) => {
711712
// This pattern component doesn't have any metacharacters, so we
@@ -715,11 +716,11 @@ fn fill_todo(todo: &mut Vec<Result<(Path, usize), GlobError>>, patterns: &[Patte
715716
// right away.
716717
let special = "." == s.as_slice() || ".." == s.as_slice();
717718
let next_path = path.join(s.as_slice());
718-
if (special && path.is_dir()) || (!special && next_path.exists()) {
719+
if (special && is_dir) || (!special && next_path.exists()) {
719720
add(todo, next_path);
720721
}
721722
},
722-
None => {
723+
None if is_dir => {
723724
match fs::readdir(path) {
724725
Ok(mut children) => {
725726
children.sort_by(|p1, p2| p2.filename().cmp(&p1.filename()));
@@ -742,6 +743,7 @@ fn fill_todo(todo: &mut Vec<Result<(Path, usize), GlobError>>, patterns: &[Patte
742743
},
743744
}
744745
}
746+
None => {/* not a directory, nothing more to find */}
745747
}
746748
}
747749

tests/glob-std.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
// ignore-windows TempDir may cause IoError on windows: #10462
12+
#![feature(path, os, io)]
1213

1314
extern crate glob;
1415

@@ -38,7 +39,7 @@ fn main() {
3839
}
3940

4041
fn glob_vec(pattern: &str) -> Vec<Path> {
41-
glob(pattern).unwrap().filter_map(|r| r.ok()).collect()
42+
glob(pattern).unwrap().map(|r| r.unwrap()).collect()
4243
}
4344

4445
let root = TempDir::new("glob-tests");

0 commit comments

Comments
 (0)