From eccb86c9edc1b36d6733de66c4e37d305090d26d Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 23 Apr 2021 08:26:20 +0200 Subject: [PATCH] ls: fix -a test --- src/uu/ls/src/ls.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index f820ffffe..19097edda 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -492,7 +492,7 @@ impl Config { } } - if files != Files::Normal { + if files == Files::Normal { ignore_patterns.add(Glob::new(".*").unwrap()); } @@ -1185,25 +1185,21 @@ fn sort_entries(entries: &mut Vec, config: &Config) { fn is_hidden(file_path: &DirEntry) -> bool { let metadata = fs::metadata(file_path.path()).unwrap(); let attr = metadata.file_attributes(); - ((attr & 0x2) > 0) || file_path.file_name().to_string_lossy().starts_with('.') -} - -#[cfg(unix)] -fn is_hidden(file_path: &DirEntry) -> bool { - file_path.file_name().to_string_lossy().starts_with('.') + ((attr & 0x2) > 0) } fn should_display(entry: &DirEntry, config: &Config) -> bool { let ffi_name = entry.file_name(); - if config.files == Files::Normal && is_hidden(entry) { - return false; + // For unix, the hidden files are already included in the ignore pattern + #[cfg(windows)] + { + if config.files == Files::Normal && is_hidden(entry) { + return false; + } } - if config.ignore_patterns.is_match(&ffi_name) { - return false; - } - true + !config.ignore_patterns.is_match(&ffi_name) } fn enter_directory(dir: &PathData, config: &Config) {