From 8f6770401df3e41161a59c6fc55a78e75e660948 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 29 Apr 2020 23:04:58 +0200 Subject: [PATCH 1/4] feat(df): Add the support of path for df. ex: df /boot --- src/uu/df/df.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/uu/df/df.rs b/src/uu/df/df.rs index 394a0ca46..6b7dfc0d9 100644 --- a/src/uu/df/df.rs +++ b/src/uu/df/df.rs @@ -100,6 +100,7 @@ static OPT_KILO: &str = "kilo"; static OPT_LOCAL: &str = "local"; static OPT_NO_SYNC: &str = "no-sync"; static OPT_OUTPUT: &str = "output"; +static OPT_PATHS: &str = "paths"; static OPT_PORTABILITY: &str = "portability"; static OPT_SYNC: &str = "sync"; static OPT_TYPE: &str = "type"; @@ -645,7 +646,7 @@ fn read_fs_list() -> Vec { } } -fn filter_mount_list(vmi: Vec, opt: &Options) -> Vec { +fn filter_mount_list(vmi: Vec, paths: &[String], opt: &Options) -> Vec { vmi.into_iter() .filter_map(|mi| { if (mi.remote && opt.show_local_fs) @@ -654,7 +655,17 @@ fn filter_mount_list(vmi: Vec, opt: &Options) -> Vec { { None } else { - Some((mi.dev_id.clone(), mi)) + if paths.is_empty() { + // No path specified + return Some((mi.dev_id.clone(), mi)); + } + if paths.contains(&mi.mount_dir) { + // One or more paths have been provided + Some((mi.dev_id.clone(), mi)) + } else { + // Not a path we want to see + None + } } }) .fold( @@ -849,6 +860,8 @@ pub fn uumain(args: Vec) -> i32 { .long("version") .help("output version information and exit"), ) + .arg(Arg::with_name(OPT_PATHS).multiple(true)) + .help("Filesystem(s) to list") .get_matches_from(&args); if matches.is_present(OPT_VERSION) { @@ -856,6 +869,11 @@ pub fn uumain(args: Vec) -> i32 { return EXIT_OK; } + let paths: Vec = matches + .values_of(OPT_PATHS) + .map(|v| v.map(ToString::to_string).collect()) + .unwrap_or_default(); + #[cfg(windows)] { if matches.is_present(OPT_INODES) { @@ -896,7 +914,7 @@ pub fn uumain(args: Vec) -> i32 { opt.fs_selector.exclude(fs_type.to_owned()); } - let fs_list = filter_mount_list(read_fs_list(), &opt) + let fs_list = filter_mount_list(read_fs_list(), &paths, &opt) .into_iter() .filter_map(Filesystem::new) .filter(|fs| fs.usage.blocks != 0 || opt.show_all_fs || opt.show_listed_fs) From c85756e50988acd79a5f1c907dd7d3fd0a3ee2b4 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 30 Apr 2020 23:02:22 +0200 Subject: [PATCH 2/4] fix(df): Linux: Fix the mount path and type --- src/uu/df/df.rs | 6 ++++-- tests/test_df.rs | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/uu/df/df.rs b/src/uu/df/df.rs index 6b7dfc0d9..732e48afb 100644 --- a/src/uu/df/df.rs +++ b/src/uu/df/df.rs @@ -356,11 +356,13 @@ impl MountInfo { #[cfg(target_os = "linux")] fn new(file_name: &str, raw: Vec<&str>) -> Option { match file_name { + // Format: 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue + // "man proc" for more details "/proc/self/mountinfo" => { let mut m = MountInfo { dev_id: "".to_string(), - dev_name: raw[8].to_string(), - fs_type: raw[7].to_string(), + dev_name: raw[9].to_string(), + fs_type: raw[8].to_string(), mount_root: raw[3].to_string(), mount_dir: raw[4].to_string(), mount_option: raw[5].to_string(), diff --git a/tests/test_df.rs b/tests/test_df.rs index e97a34b49..03903049a 100644 --- a/tests/test_df.rs +++ b/tests/test_df.rs @@ -6,4 +6,11 @@ fn test_df_compatible() { let result = ucmd.arg("-ah").run(); assert!(result.success); } + +#[test] +fn test_df_compatible_type() { + let (_, mut ucmd) = at_and_ucmd!(); + let result = ucmd.arg("-aT").run(); + assert!(result.success); +} // TODO From 8d1f0edfc43aefa823c250fd172c53bc9da897f5 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 30 Apr 2020 23:07:22 +0200 Subject: [PATCH 3/4] refact(df): follow the same directory pattern than the other software --- src/uu/df/Cargo.toml | 4 ++-- src/uu/df/main.rs | 5 ----- src/uu/df/{ => src}/df.rs | 0 3 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 src/uu/df/main.rs rename src/uu/df/{ => src}/df.rs (100%) diff --git a/src/uu/df/Cargo.toml b/src/uu/df/Cargo.toml index 601a5acec..5fc2e3502 100644 --- a/src/uu/df/Cargo.toml +++ b/src/uu/df/Cargo.toml @@ -5,7 +5,7 @@ authors = [] [lib] name = "uu_df" -path = "df.rs" +path = "src/df.rs" [dependencies] clap = "2.32.0" @@ -18,4 +18,4 @@ winapi = { version = "0.3", features = ["handleapi"] } [[bin]] name = "df" -path = "main.rs" +path = "../../common/uumain.rs" diff --git a/src/uu/df/main.rs b/src/uu/df/main.rs deleted file mode 100644 index 09d4f3790..000000000 --- a/src/uu/df/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -extern crate uu_df; - -fn main() { - std::process::exit(uu_df::uumain(std::env::args().collect())); -} diff --git a/src/uu/df/df.rs b/src/uu/df/src/df.rs similarity index 100% rename from src/uu/df/df.rs rename to src/uu/df/src/df.rs From 2d5d0680d83c6148aacc7b72849ffdc7d1194e19 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 3 May 2020 12:00:42 -0500 Subject: [PATCH 4/4] fix(df) ~ fix lint complaint (unused import) --- src/uu/df/src/df.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 732e48afb..764182e03 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -30,7 +30,6 @@ use kernel32::{ use std::cell::Cell; use std::collections::HashMap; use std::collections::HashSet; -use std::env; #[cfg(unix)] use std::ffi::CString;