Skip to content

Commit 637fac2

Browse files
committed
---
yaml --- r: 150683 b: refs/heads/try2 c: 1700f35 h: refs/heads/master i: 150681: caada66 150679: cb41521 v: v3
1 parent 1dc23c8 commit 637fac2

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 4051bd900abbb47557dd8928532eedbc2bca0563
8+
refs/heads/try2: 1700f359bc5d6b8086194e3cc0f3698666dd41a4
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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/try2/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)