mirror of
https://github.com/bootandy/dust.git
synced 2025-12-05 20:40:11 -08:00
perf: Canonicalize ignored absolute path only once
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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::<Vec<PathBuf>>(),
|
||||
None => vec![],
|
||||
};
|
||||
|
||||
12
src/utils.rs
12
src/utils.rs
@@ -67,6 +67,18 @@ pub fn normalize_path<P: AsRef<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
|
||||
|
||||
Reference in New Issue
Block a user