mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
ls: use globset instead of glob
This commit is contained in:
parent
bbb27800c9
commit
5134348a11
2 changed files with 17 additions and 12 deletions
|
@ -22,7 +22,7 @@ term_grid = "0.1.5"
|
|||
termsize = "0.1.6"
|
||||
time = "0.1.40"
|
||||
unicode-width = "0.1.5"
|
||||
glob = "0.3.0"
|
||||
globset = "0.4.6"
|
||||
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["entries", "fs"] }
|
||||
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ mod quoting_style;
|
|||
mod version_cmp;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use glob;
|
||||
use globset::{self, Glob, GlobSet, GlobSetBuilder};
|
||||
use number_prefix::NumberPrefix;
|
||||
use quoting_style::{escape_name, QuotingStyle};
|
||||
#[cfg(unix)]
|
||||
|
@ -194,7 +194,7 @@ struct Config {
|
|||
recursive: bool,
|
||||
reverse: bool,
|
||||
dereference: bool,
|
||||
ignore_patterns: Vec<glob::Pattern>,
|
||||
ignore_patterns: GlobSet,
|
||||
size_format: SizeFormat,
|
||||
directory: bool,
|
||||
time: Time,
|
||||
|
@ -440,28 +440,34 @@ impl Config {
|
|||
IndicatorStyle::None
|
||||
};
|
||||
|
||||
let mut ignore_patterns = Vec::new();
|
||||
let mut ignore_patterns = GlobSetBuilder::new();
|
||||
if options.is_present(options::IGNORE_BACKUPS) {
|
||||
ignore_patterns.push(glob::Pattern::new("*~").unwrap());
|
||||
ignore_patterns.push(glob::Pattern::new(".*~").unwrap());
|
||||
ignore_patterns.add(Glob::new("*~").unwrap());
|
||||
ignore_patterns.add(Glob::new(".*~").unwrap());
|
||||
}
|
||||
|
||||
for pattern in options.values_of(options::IGNORE).into_iter().flatten() {
|
||||
match glob::Pattern::new(pattern) {
|
||||
Ok(p) => ignore_patterns.push(p),
|
||||
match Glob::new(pattern) {
|
||||
Ok(p) => {
|
||||
ignore_patterns.add(p);
|
||||
}
|
||||
Err(_) => show_warning!("Invalid pattern for ignore: '{}'", pattern),
|
||||
}
|
||||
}
|
||||
|
||||
if files == Files::Normal {
|
||||
for pattern in options.values_of(options::HIDE).into_iter().flatten() {
|
||||
match glob::Pattern::new(pattern) {
|
||||
Ok(p) => ignore_patterns.push(p),
|
||||
match Glob::new(pattern) {
|
||||
Ok(p) => {
|
||||
ignore_patterns.add(p);
|
||||
}
|
||||
Err(_) => show_warning!("Invalid pattern for hide: '{}'", pattern),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let ignore_patterns = ignore_patterns.build().unwrap();
|
||||
|
||||
Config {
|
||||
format,
|
||||
files,
|
||||
|
@ -1023,13 +1029,12 @@ fn is_hidden(file_path: &DirEntry) -> bool {
|
|||
|
||||
fn should_display(entry: &DirEntry, config: &Config) -> bool {
|
||||
let ffi_name = entry.file_name();
|
||||
let name = ffi_name.to_string_lossy();
|
||||
|
||||
if config.files == Files::Normal && is_hidden(entry) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if config.ignore_patterns.iter().any(|p| p.matches(&name)) {
|
||||
if config.ignore_patterns.is_match(&ffi_name) {
|
||||
return false;
|
||||
}
|
||||
true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue