From 815331acadeef4fd7be6b2825912ca464bdd1ba7 Mon Sep 17 00:00:00 2001 From: Willians Faria Date: Mon, 4 Mar 2024 22:32:15 -0300 Subject: [PATCH] fix: skipping children expansion when ignore_glob ends with /* --- src/fs/filter.rs | 11 +++++++++++ src/output/details.rs | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/fs/filter.rs b/src/fs/filter.rs index 162cf0ac0..1cdc32f92 100644 --- a/src/fs/filter.rs +++ b/src/fs/filter.rs @@ -94,6 +94,17 @@ impl FileFilter { } } + /// checks if a dirname, when appended with a `/` matches any + /// of the ignore patterns provided as argument. + /// + /// this only exists since when creating the patterns, any glob + /// that ends with `/` or `/*` will keep the `/` on the pattern, + /// and when listing directories, we display them without any `/` + pub fn should_skip_expansion(&self, dirname: &str) -> bool { + let dirname_with_slash = format!("{dirname}/"); + self.ignore_patterns.is_ignored(&dirname_with_slash) + } + /// Remove every file in the given vector that does *not* pass the /// filter predicate for file names specified on the command-line. /// diff --git a/src/output/details.rs b/src/output/details.rs index 13fa5165e..acca2bbd2 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -286,7 +286,11 @@ impl<'a> Render<'a> { let mut dir = None; if let Some(r) = self.recurse { - if file.is_directory() && r.tree && !r.is_too_deep(depth.0) { + if file.is_directory() + && r.tree + && !r.is_too_deep(depth.0) + && !self.filter.should_skip_expansion(&file.name) + { trace!("matching on to_dir"); match file.to_dir() { Ok(d) => {