From cd8790239f3ad8a3d532e1ec66527dc0b7d6b3c0 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 8 Apr 2025 16:27:18 -0400 Subject: [PATCH] find: Fix -fstype with stacked mounts If you stack two mounts on top of each other, e.g. # mount -t ext4 /dev/sdX /mnt # mount -t f2fs /dev/sdY /mnt then read_fs_list() will return two entries for that mount point. The later one is the one with the correct type, since the later mount is on top of the earlier one. --- src/find/matchers/fs.rs | 3 ++- src/find/matchers/printf.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/find/matchers/fs.rs b/src/find/matchers/fs.rs index ee53c367..051604c3 100644 --- a/src/find/matchers/fs.rs +++ b/src/find/matchers/fs.rs @@ -53,7 +53,8 @@ pub fn get_file_system_type(path: &Path, cache: &RefCell>) -> URes let fs_list = uucore::fsext::read_fs_list()?; let result = fs_list .into_iter() - .find(|fs| fs.dev_id == dev_id) + .filter(|fs| fs.dev_id == dev_id) + .next_back() .map_or_else(String::new, |fs| fs.fs_type); // cache the latest query if not a match before diff --git a/src/find/matchers/printf.rs b/src/find/matchers/printf.rs index c7b6e196..d018ff06 100644 --- a/src/find/matchers/printf.rs +++ b/src/find/matchers/printf.rs @@ -451,7 +451,8 @@ fn format_directive<'entry>( uucore::fsext::read_fs_list().expect("Could not find the filesystem info"); fs_list .into_iter() - .find(|fs| fs.dev_id == dev_id) + .filter(|fs| fs.dev_id == dev_id) + .next_back() .map_or_else(String::new, |fs| fs.fs_type) .into() }