From 58c9f6d5092d1fa3114d339427187b42fe863b15 Mon Sep 17 00:00:00 2001 From: Jan Chren ~rindeal Date: Mon, 24 Jun 2024 04:29:05 +0000 Subject: [PATCH] Fix -x option behavior This PR addresses an issue where `target_dirs` were being optimized out\ before being passed to the `get_filesystem_devices()` function. The changes in this PR ensure that `target_dirs` are passed directly to `get_filesystem_devices()`, and only then are they simplified. Example of a command that currently doesn't work correctly: ```sh dust -x $(findmnt -S tmpfs -o target -n) ``` It should show the usage of all tmpfs mounts, but it currently shows just the the root mountpoints like `/run`, since all the mountpoints nested under it are optimized out. --- src/main.rs | 4 ++-- src/utils.rs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index f62a996..0354cef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -192,10 +192,10 @@ fn main() { let limit_filesystem = options.get_flag("limit_filesystem"); let follow_links = options.get_flag("dereference_links"); - let simplified_dirs = simplify_dir_names(target_dirs); let allowed_filesystems = limit_filesystem - .then(|| get_filesystem_devices(simplified_dirs.iter())) + .then(|| get_filesystem_devices(target_dirs.iter().cloned())) .unwrap_or_default(); + let simplified_dirs = simplify_dir_names(target_dirs); let ignored_full_path: HashSet = ignore_directories .into_iter() diff --git a/src/utils.rs b/src/utils.rs index 4d8bdab..e85c718 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -34,11 +34,12 @@ pub fn simplify_dir_names>(filenames: Vec

) -> HashSet top_level_names } -pub fn get_filesystem_devices<'a, P: IntoIterator>(paths: P) -> HashSet { +pub fn get_filesystem_devices<'a, P: IntoIterator>(paths: P) -> HashSet { // Gets the device ids for the filesystems which are used by the argument paths paths .into_iter() - .filter_map(|p| match get_metadata(p, false) { + .map(PathBuf::from) + .filter_map(|p| match get_metadata(&p, false) { Some((_size, Some((_id, dev)), _time)) => Some(dev), _ => None, })