mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #1135 from jamessan/stat-cleanup
stat: Minor improvements
This commit is contained in:
commit
875a84c176
1 changed files with 19 additions and 11 deletions
|
@ -202,7 +202,7 @@ pub struct Stater {
|
||||||
showfs: bool,
|
showfs: bool,
|
||||||
from_user: bool,
|
from_user: bool,
|
||||||
files: Vec<String>,
|
files: Vec<String>,
|
||||||
mount_list: Vec<String>,
|
mount_list: Option<Vec<String>>,
|
||||||
default_tokens: Vec<Token>,
|
default_tokens: Vec<Token>,
|
||||||
default_dev_tokens: Vec<Token>,
|
default_dev_tokens: Vec<Token>,
|
||||||
}
|
}
|
||||||
|
@ -471,13 +471,19 @@ impl Stater {
|
||||||
let default_dev_tokens = Stater::generate_tokens(&Stater::default_fmt(showfs, terse, true), use_printf)
|
let default_dev_tokens = Stater::generate_tokens(&Stater::default_fmt(showfs, terse, true), use_printf)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let reader = BufReader::new(File::open(MOUNT_INFO).expect("Failed to read /etc/mtab"));
|
let mount_list = if showfs {
|
||||||
let mut mount_list = reader.lines()
|
// mount points aren't displayed when showing filesystem information
|
||||||
.filter_map(|s| s.ok())
|
None
|
||||||
.filter_map(|line| line.split_whitespace().nth(1).map(|s| s.to_owned()))
|
} else {
|
||||||
.collect::<Vec<String>>();
|
let reader = BufReader::new(File::open(MOUNT_INFO).expect(&format!("Failed to read {}", MOUNT_INFO)));
|
||||||
// Reverse sort. The longer comes first.
|
let mut mount_list = reader.lines()
|
||||||
mount_list.sort_by(|a, b| b.cmp(a));
|
.filter_map(|s| s.ok())
|
||||||
|
.filter_map(|line| line.split_whitespace().nth(1).map(|s| s.to_owned()))
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
// Reverse sort. The longer comes first.
|
||||||
|
mount_list.sort_by(|a, b| b.cmp(a));
|
||||||
|
Some(mount_list)
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Stater {
|
Ok(Stater {
|
||||||
follow: matches.opt_present("dereference"),
|
follow: matches.opt_present("dereference"),
|
||||||
|
@ -495,9 +501,11 @@ impl Stater {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(_) => return None,
|
Err(_) => return None,
|
||||||
};
|
};
|
||||||
for root in (&self.mount_list).into_iter() {
|
if let Some(ref mount_list) = self.mount_list {
|
||||||
if path.starts_with(root) {
|
for root in mount_list.into_iter() {
|
||||||
return Some(root.clone());
|
if path.starts_with(root) {
|
||||||
|
return Some(root.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue