Skip to content

Respect require_literal_leading_dot option in glob_with method for path components #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,9 @@ fn fill_todo(
});
match dirs {
Ok(mut children) => {
if options.require_literal_leading_dot {
children.retain(|x| !x.file_name().unwrap().to_str().unwrap().starts_with("."));
}
children.sort_by(|p1, p2| p2.file_name().cmp(&p1.file_name()));
todo.extend(children.into_iter().map(|x| Ok((x, idx))));

Expand Down
27 changes: 26 additions & 1 deletion tests/glob-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
extern crate glob;
extern crate tempdir;

use glob::glob;
use glob::{glob, glob_with};
use std::env;
use std::fs;
use std::path::PathBuf;
Expand All @@ -35,6 +35,10 @@ fn main() {
glob(pattern).unwrap().map(|r| r.unwrap()).collect()
}

fn glob_with_vec(pattern: &str, options: glob::MatchOptions) -> Vec<PathBuf> {
glob_with(pattern, options).unwrap().map(|r| r.unwrap()).collect()
}

let root = TempDir::new("glob-tests");
let root = root.ok().expect("Should have created a temp directory");
assert!(env::set_current_dir(root.path()).is_ok());
Expand Down Expand Up @@ -288,6 +292,27 @@ fn main() {
vec!(PathBuf::from("bbb/specials/]"))
);

mk_file("i", true);
mk_file("i/qwe", true);
mk_file("i/qwe/.aaa", false);
mk_file("i/qwe/.bbb", true);
mk_file("i/qwe/.bbb/ccc", false);
mk_file("i/qwe/.bbb/.ddd", false);
mk_file("i/qwe/eee", false);

let options = glob::MatchOptions {
case_sensitive: false,
require_literal_separator: true,
require_literal_leading_dot: true,
};
assert_eq!(glob_with_vec("i/**/*a*", options), Vec::<PathBuf>::new());
assert_eq!(glob_with_vec("i/**/*c*", options), Vec::<PathBuf>::new());
assert_eq!(glob_with_vec("i/**/*d*", options), Vec::<PathBuf>::new());
assert_eq!(
glob_with_vec("i/**/*e*", options),
vec!(PathBuf::from("i/qwe"), PathBuf::from("i/qwe/eee"))
);

if env::consts::FAMILY != "windows" {
assert_eq!(
glob_vec("bbb/specials/[*]"),
Expand Down