mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +00:00
stat: Avoid parsing mount info when showing filesystem info
This commit is contained in:
parent
72b4629916
commit
81eef5dabf
1 changed files with 19 additions and 11 deletions
|
@ -202,7 +202,7 @@ pub struct Stater {
|
|||
showfs: bool,
|
||||
from_user: bool,
|
||||
files: Vec<String>,
|
||||
mount_list: Vec<String>,
|
||||
mount_list: Option<Vec<String>>,
|
||||
default_tokens: Vec<Token>,
|
||||
default_dev_tokens: Vec<Token>,
|
||||
}
|
||||
|
@ -471,6 +471,10 @@ impl Stater {
|
|||
let default_dev_tokens = Stater::generate_tokens(&Stater::default_fmt(showfs, terse, true), use_printf)
|
||||
.unwrap();
|
||||
|
||||
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())
|
||||
|
@ -478,6 +482,8 @@ impl Stater {
|
|||
.collect::<Vec<String>>();
|
||||
// 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,11 +501,13 @@ impl Stater {
|
|||
Ok(s) => s,
|
||||
Err(_) => return None,
|
||||
};
|
||||
for root in (&self.mount_list).into_iter() {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue