diff --git a/src/dir_walker.rs b/src/dir_walker.rs index b4f1846..6e28963 100644 --- a/src/dir_walker.rs +++ b/src/dir_walker.rs @@ -132,19 +132,14 @@ fn is_ignored_path(path: &Path, walk_data: &WalkData) -> bool { } // Entry is inside an ignored absolute path + // Absolute paths should be canonicalized before being added to `WalkData.ignore_directories` for ignored_path in walk_data.ignore_directories.iter() { if !ignored_path.is_absolute() { continue; } - match std::fs::canonicalize(ignored_path) { - Ok(absolute_ignored_path) => { - let absolute_entry_path = - std::fs::canonicalize(path).unwrap_or_default(); - if absolute_entry_path.starts_with(absolute_ignored_path) { - return true; - } - } - Err(_) => continue, + let absolute_entry_path = std::fs::canonicalize(path).unwrap_or_default(); + if absolute_entry_path.starts_with(ignored_path) { + return true; } } diff --git a/src/main.rs b/src/main.rs index 3bfc8d7..bfe7a5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,7 @@ use std::sync::atomic::Ordering; use std::sync::Arc; use std::sync::Mutex; use sysinfo::{System, SystemExt}; +use utils::canonicalize_absolute_path; use self::display::draw_it; use config::get_config; @@ -198,6 +199,7 @@ fn main() { Some(values) => values .map(|v| v.as_str()) .map(PathBuf::from) + .map(canonicalize_absolute_path) .collect::>(), None => vec![], }; diff --git a/src/utils.rs b/src/utils.rs index 1f2fb42..e02ff7a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -67,6 +67,18 @@ pub fn normalize_path>(path: P) -> PathBuf { path.as_ref().components().collect() } +// Canonicalize the path only if it is an absolute path +pub fn canonicalize_absolute_path(path: PathBuf) -> PathBuf { + if path.is_absolute() { + match std::fs::canonicalize(&path) { + Ok(canonicalized_path) => canonicalized_path, + Err(_) => path, + } + } else { + path + } +} + pub fn is_filtered_out_due_to_regex(filter_regex: &[Regex], dir: &Path) -> bool { if filter_regex.is_empty() { false