|
25 | 25 | html_root_url = "http://doc.rust-lang.org/glob/")]
|
26 | 26 | #![cfg_attr(test, feature(io))]
|
27 | 27 | #![cfg_attr(all(test, windows), feature(std_misc))]
|
28 |
| -#![feature(path_components_peek, unmarked_api)] |
29 | 28 |
|
30 | 29 | use std::ascii::AsciiExt;
|
31 | 30 | use std::cell::Cell;
|
@@ -154,15 +153,18 @@ pub fn glob_with(pattern: &str, options: &MatchOptions)
|
154 | 153 | #[cfg(not(windows))]
|
155 | 154 | fn to_scope(p: &Path) -> PathBuf { p.to_path_buf() }
|
156 | 155 |
|
157 |
| - let mut components = Path::new(pattern).components(); |
| 156 | + let mut components = Path::new(pattern).components().peekable(); |
158 | 157 | loop {
|
159 | 158 | match components.peek() {
|
160 |
| - Some(Component::Prefix(..)) | |
161 |
| - Some(Component::RootDir) => { components.next(); } |
| 159 | + Some(&Component::Prefix(..)) | |
| 160 | + Some(&Component::RootDir) => { components.next(); } |
162 | 161 | _ => break,
|
163 | 162 | }
|
164 | 163 | }
|
165 |
| - let root_len = pattern.len() - components.as_path().to_str().unwrap().len(); |
| 164 | + let rest = components.map(|s| s.as_os_str()).collect::<PathBuf>(); |
| 165 | + let normalized_pattern = Path::new(pattern).iter().collect::<PathBuf>(); |
| 166 | + let root_len = normalized_pattern.to_str().unwrap().len() - |
| 167 | + rest.to_str().unwrap().len(); |
166 | 168 | let root = if root_len > 0 {Some(Path::new(&pattern[..root_len]))}
|
167 | 169 | else {None};
|
168 | 170 |
|
@@ -190,6 +192,14 @@ pub fn glob_with(pattern: &str, options: &MatchOptions)
|
190 | 192 | dir_patterns.push(compiled);
|
191 | 193 | }
|
192 | 194 |
|
| 195 | + if root_len == pattern.len() { |
| 196 | + dir_patterns.push(Pattern { |
| 197 | + original: "".to_string(), |
| 198 | + tokens: Vec::new(), |
| 199 | + is_recursive: false, |
| 200 | + }); |
| 201 | + } |
| 202 | + |
193 | 203 | let require_dir = pattern.chars().next_back().map(path::is_separator) == Some(true);
|
194 | 204 | let todo = Vec::new();
|
195 | 205 |
|
|
0 commit comments