From c2a4c4573a62b2115f5d4b4ed85f971cfeac5515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teemu=20P=C3=A4tsi?= Date: Fri, 7 Mar 2025 01:18:31 +0200 Subject: [PATCH] fix: Ignoring absolute path with `-X` option --- src/dir_walker.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/dir_walker.rs b/src/dir_walker.rs index e1aa00d..a40c79d 100644 --- a/src/dir_walker.rs +++ b/src/dir_walker.rs @@ -175,6 +175,20 @@ fn ignore_file(entry: &DirEntry, walk_data: &WalkData) -> bool { return true; } + // Entry is inside an ignored absolute path + for ignored_path in walk_data.ignore_directories.iter() { + match std::fs::canonicalize(ignored_path) { + Ok(absolute_ignored_path) => { + let absolute_entry_path = + std::fs::canonicalize(&entry.path()).unwrap_or(PathBuf::new()); + if absolute_entry_path.starts_with(absolute_ignored_path) { + return true; + } + } + Err(_) => continue, + } + } + (is_dot_file && walk_data.ignore_hidden) || is_ignored_path }