libglob: allow "." and ".." to be matched
... also don't read the whole directory if the glob for that path component doesn't contain any metacharacters. Patterns like `../*.jpg` will work now, and `.*` will match both `.` and `..` to be consistent with shell expansion. As before: Just `*` still won't match `.` and `..`, while it will still match dotfiles like `.git` by default.
This commit is contained in:
parent
f1f50565a1
commit
4051bd900a
2 changed files with 98 additions and 16 deletions
|
|
@ -11,13 +11,12 @@
|
|||
// ignore-fast check-fast doesn't like 'extern crate extra'
|
||||
// ignore-win32 TempDir may cause IoError on windows: #10462
|
||||
|
||||
#[feature(macro_rules)];
|
||||
#![feature(macro_rules)]
|
||||
|
||||
extern crate glob;
|
||||
|
||||
use glob::glob;
|
||||
use std::unstable::finally::Finally;
|
||||
use std::{os, unstable};
|
||||
use std::os;
|
||||
use std::io;
|
||||
use std::io::TempDir;
|
||||
|
||||
|
|
@ -30,9 +29,9 @@ macro_rules! assert_eq ( ($e1:expr, $e2:expr) => (
|
|||
pub fn main() {
|
||||
fn mk_file(path: &str, directory: bool) {
|
||||
if directory {
|
||||
io::fs::mkdir(&Path::new(path), io::UserRWX);
|
||||
io::fs::mkdir(&Path::new(path), io::UserRWX).unwrap();
|
||||
} else {
|
||||
io::File::create(&Path::new(path));
|
||||
io::File::create(&Path::new(path)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,8 +72,8 @@ pub fn main() {
|
|||
mk_file("xyz/z", false);
|
||||
|
||||
assert_eq!(glob_vec(""), Vec::new());
|
||||
assert_eq!(glob_vec("."), Vec::new());
|
||||
assert_eq!(glob_vec(".."), Vec::new());
|
||||
assert_eq!(glob_vec("."), vec!(os::getcwd()));
|
||||
assert_eq!(glob_vec(".."), vec!(os::getcwd().join("..")));
|
||||
|
||||
assert_eq!(glob_vec("aaa"), vec!(abs_path("aaa")));
|
||||
assert_eq!(glob_vec("aaa/"), vec!(abs_path("aaa")));
|
||||
|
|
@ -132,6 +131,13 @@ pub fn main() {
|
|||
abs_path("aaa/tomato/tomato.txt"),
|
||||
abs_path("aaa/tomato/tomoto.txt")));
|
||||
|
||||
assert_eq!(glob_vec("./aaa"), vec!(abs_path("aaa")));
|
||||
assert_eq!(glob_vec("./*"), glob_vec("*"));
|
||||
assert_eq!(glob_vec("*/..").pop().unwrap(), abs_path("."));
|
||||
assert_eq!(glob_vec("aaa/../bbb"), vec!(abs_path("bbb")));
|
||||
assert_eq!(glob_vec("nonexistent/../bbb"), Vec::new());
|
||||
assert_eq!(glob_vec("aaa/tomato/tomato.txt/.."), Vec::new());
|
||||
|
||||
assert_eq!(glob_vec("aa[a]"), vec!(abs_path("aaa")));
|
||||
assert_eq!(glob_vec("aa[abc]"), vec!(abs_path("aaa")));
|
||||
assert_eq!(glob_vec("a[bca]a"), vec!(abs_path("aaa")));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue