mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +00:00
Merge pull request #1488 from sylvestre/df-path
feat(df): Add the support of path for df (eg, `df /boot`)
This commit is contained in:
commit
ecfb42ba6c
4 changed files with 34 additions and 13 deletions
|
@ -5,7 +5,7 @@ authors = []
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "uu_df"
|
name = "uu_df"
|
||||||
path = "df.rs"
|
path = "src/df.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.32.0"
|
clap = "2.32.0"
|
||||||
|
@ -18,4 +18,4 @@ winapi = { version = "0.3", features = ["handleapi"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "df"
|
name = "df"
|
||||||
path = "main.rs"
|
path = "../../common/uumain.rs"
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
extern crate uu_df;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
std::process::exit(uu_df::uumain(std::env::args().collect()));
|
|
||||||
}
|
|
|
@ -30,7 +30,6 @@ use kernel32::{
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::env;
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
@ -100,6 +99,7 @@ static OPT_KILO: &str = "kilo";
|
||||||
static OPT_LOCAL: &str = "local";
|
static OPT_LOCAL: &str = "local";
|
||||||
static OPT_NO_SYNC: &str = "no-sync";
|
static OPT_NO_SYNC: &str = "no-sync";
|
||||||
static OPT_OUTPUT: &str = "output";
|
static OPT_OUTPUT: &str = "output";
|
||||||
|
static OPT_PATHS: &str = "paths";
|
||||||
static OPT_PORTABILITY: &str = "portability";
|
static OPT_PORTABILITY: &str = "portability";
|
||||||
static OPT_SYNC: &str = "sync";
|
static OPT_SYNC: &str = "sync";
|
||||||
static OPT_TYPE: &str = "type";
|
static OPT_TYPE: &str = "type";
|
||||||
|
@ -355,11 +355,13 @@ impl MountInfo {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn new(file_name: &str, raw: Vec<&str>) -> Option<MountInfo> {
|
fn new(file_name: &str, raw: Vec<&str>) -> Option<MountInfo> {
|
||||||
match file_name {
|
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" => {
|
"/proc/self/mountinfo" => {
|
||||||
let mut m = MountInfo {
|
let mut m = MountInfo {
|
||||||
dev_id: "".to_string(),
|
dev_id: "".to_string(),
|
||||||
dev_name: raw[8].to_string(),
|
dev_name: raw[9].to_string(),
|
||||||
fs_type: raw[7].to_string(),
|
fs_type: raw[8].to_string(),
|
||||||
mount_root: raw[3].to_string(),
|
mount_root: raw[3].to_string(),
|
||||||
mount_dir: raw[4].to_string(),
|
mount_dir: raw[4].to_string(),
|
||||||
mount_option: raw[5].to_string(),
|
mount_option: raw[5].to_string(),
|
||||||
|
@ -645,7 +647,7 @@ fn read_fs_list() -> Vec<MountInfo> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter_mount_list(vmi: Vec<MountInfo>, opt: &Options) -> Vec<MountInfo> {
|
fn filter_mount_list(vmi: Vec<MountInfo>, paths: &[String], opt: &Options) -> Vec<MountInfo> {
|
||||||
vmi.into_iter()
|
vmi.into_iter()
|
||||||
.filter_map(|mi| {
|
.filter_map(|mi| {
|
||||||
if (mi.remote && opt.show_local_fs)
|
if (mi.remote && opt.show_local_fs)
|
||||||
|
@ -654,7 +656,17 @@ fn filter_mount_list(vmi: Vec<MountInfo>, opt: &Options) -> Vec<MountInfo> {
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} 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(
|
.fold(
|
||||||
|
@ -849,6 +861,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
.long("version")
|
.long("version")
|
||||||
.help("output version information and exit"),
|
.help("output version information and exit"),
|
||||||
)
|
)
|
||||||
|
.arg(Arg::with_name(OPT_PATHS).multiple(true))
|
||||||
|
.help("Filesystem(s) to list")
|
||||||
.get_matches_from(&args);
|
.get_matches_from(&args);
|
||||||
|
|
||||||
if matches.is_present(OPT_VERSION) {
|
if matches.is_present(OPT_VERSION) {
|
||||||
|
@ -856,6 +870,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
return EXIT_OK;
|
return EXIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let paths: Vec<String> = matches
|
||||||
|
.values_of(OPT_PATHS)
|
||||||
|
.map(|v| v.map(ToString::to_string).collect())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
if matches.is_present(OPT_INODES) {
|
if matches.is_present(OPT_INODES) {
|
||||||
|
@ -896,7 +915,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
opt.fs_selector.exclude(fs_type.to_owned());
|
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()
|
.into_iter()
|
||||||
.filter_map(Filesystem::new)
|
.filter_map(Filesystem::new)
|
||||||
.filter(|fs| fs.usage.blocks != 0 || opt.show_all_fs || opt.show_listed_fs)
|
.filter(|fs| fs.usage.blocks != 0 || opt.show_all_fs || opt.show_listed_fs)
|
|
@ -6,4 +6,11 @@ fn test_df_compatible() {
|
||||||
let result = ucmd.arg("-ah").run();
|
let result = ucmd.arg("-ah").run();
|
||||||
assert!(result.success);
|
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
|
// TODO
|
||||||
|
|
Loading…
Reference in a new issue