Skip to content

Commit d356804

Browse files
committed
---
yaml --- r: 110526 b: refs/heads/snap-stage3 c: 1700f35 h: refs/heads/master v: v3
1 parent df6aef2 commit d356804

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e415c25bcd81dc1f9a5a3d25d9b48ed2d545336b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 4051bd900abbb47557dd8928532eedbc2bca0563
4+
refs/heads/snap-stage3: 1700f359bc5d6b8086194e3cc0f3698666dd41a4
55
refs/heads/try: 597a645456b55e1c886ce15d23a192abdf4d55cf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libglob/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use std::path::is_sep;
4343
pub 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);

branches/snap-stage3/src/test/run-pass/glob-std.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ pub fn main() {
138138
assert_eq!(glob_vec("nonexistent/../bbb"), Vec::new());
139139
assert_eq!(glob_vec("aaa/tomato/tomato.txt/.."), Vec::new());
140140

141+
assert_eq!(glob_vec("aaa/tomato/tomato.txt/"), Vec::new());
142+
141143
assert_eq!(glob_vec("aa[a]"), vec!(abs_path("aaa")));
142144
assert_eq!(glob_vec("aa[abc]"), vec!(abs_path("aaa")));
143145
assert_eq!(glob_vec("a[bca]a"), vec!(abs_path("aaa")));

0 commit comments

Comments
 (0)