From 81eef5dabfe5e4ed2774cc7da8c1416e7f84c810 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 14 Jan 2018 14:35:58 -0500 Subject: [PATCH 1/2] stat: Avoid parsing mount info when showing filesystem info --- src/stat/stat.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/stat/stat.rs b/src/stat/stat.rs index 9786d2b94..73d507383 100644 --- a/src/stat/stat.rs +++ b/src/stat/stat.rs @@ -202,7 +202,7 @@ pub struct Stater { showfs: bool, from_user: bool, files: Vec, - mount_list: Vec, + mount_list: Option>, default_tokens: Vec, default_dev_tokens: Vec, } @@ -471,13 +471,19 @@ impl Stater { let default_dev_tokens = Stater::generate_tokens(&Stater::default_fmt(showfs, terse, true), use_printf) .unwrap(); - let reader = BufReader::new(File::open(MOUNT_INFO).expect("Failed to read /etc/mtab")); - let mut mount_list = reader.lines() - .filter_map(|s| s.ok()) - .filter_map(|line| line.split_whitespace().nth(1).map(|s| s.to_owned())) - .collect::>(); - // Reverse sort. The longer comes first. - mount_list.sort_by(|a, b| b.cmp(a)); + let mount_list = if showfs { + // mount points aren't displayed when showing filesystem information + None + } else { + let reader = BufReader::new(File::open(MOUNT_INFO).expect("Failed to read /etc/mtab")); + let mut mount_list = reader.lines() + .filter_map(|s| s.ok()) + .filter_map(|line| line.split_whitespace().nth(1).map(|s| s.to_owned())) + .collect::>(); + // Reverse sort. The longer comes first. + mount_list.sort_by(|a, b| b.cmp(a)); + Some(mount_list) + }; Ok(Stater { follow: matches.opt_present("dereference"), @@ -495,9 +501,11 @@ impl Stater { Ok(s) => s, Err(_) => return None, }; - for root in (&self.mount_list).into_iter() { - if path.starts_with(root) { - return Some(root.clone()); + if let Some(ref mount_list) = self.mount_list { + for root in mount_list.into_iter() { + if path.starts_with(root) { + return Some(root.clone()); + } } } None From c82e94cae5a8f735a1837e4997651ebd38ef2eb9 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 14 Jan 2018 14:52:24 -0500 Subject: [PATCH 2/2] stat: Remove hard-coded path for mount information --- src/stat/stat.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stat/stat.rs b/src/stat/stat.rs index 73d507383..7acad72fe 100644 --- a/src/stat/stat.rs +++ b/src/stat/stat.rs @@ -475,7 +475,7 @@ impl Stater { // mount points aren't displayed when showing filesystem information None } else { - let reader = BufReader::new(File::open(MOUNT_INFO).expect("Failed to read /etc/mtab")); + let reader = BufReader::new(File::open(MOUNT_INFO).expect(&format!("Failed to read {}", MOUNT_INFO))); let mut mount_list = reader.lines() .filter_map(|s| s.ok()) .filter_map(|line| line.split_whitespace().nth(1).map(|s| s.to_owned()))