mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
parent
4ea443bf42
commit
2d4552cce4
2 changed files with 58 additions and 15 deletions
|
@ -292,7 +292,7 @@ fn get_all_filesystems(opt: &Options) -> Vec<Filesystem> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For each path, get the filesystem that contains that path.
|
/// For each path, get the filesystem that contains that path.
|
||||||
fn get_named_filesystems<P>(paths: &[P]) -> Vec<Filesystem>
|
fn get_named_filesystems<P>(paths: &[P], opt: &Options) -> Vec<Filesystem>
|
||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
{
|
{
|
||||||
|
@ -302,21 +302,35 @@ where
|
||||||
// considered. The "lofs" filesystem is a loopback
|
// considered. The "lofs" filesystem is a loopback
|
||||||
// filesystem present on Solaris and FreeBSD systems. It
|
// filesystem present on Solaris and FreeBSD systems. It
|
||||||
// is similar to a symbolic link.
|
// is similar to a symbolic link.
|
||||||
let mounts: Vec<MountInfo> = read_fs_list()
|
let mounts: Vec<MountInfo> = filter_mount_list(read_fs_list(), opt)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|mi| mi.fs_type != "lofs" && !mi.dummy)
|
.filter(|mi| mi.fs_type != "lofs" && !mi.dummy)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let mut result = vec![];
|
||||||
|
|
||||||
|
// this happens if the file system type doesn't exist
|
||||||
|
if mounts.is_empty() {
|
||||||
|
show!(USimpleError::new(1, "no file systems processed"));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert each path into a `Filesystem`, which contains
|
// Convert each path into a `Filesystem`, which contains
|
||||||
// both the mount information and usage information.
|
// both the mount information and usage information.
|
||||||
let mut result = vec![];
|
|
||||||
for path in paths {
|
for path in paths {
|
||||||
match Filesystem::from_path(&mounts, path) {
|
match Filesystem::from_path(&mounts, path) {
|
||||||
Some(fs) => result.push(fs),
|
Some(fs) => result.push(fs),
|
||||||
None => show!(USimpleError::new(
|
None => {
|
||||||
|
// this happens if specified file system type != file system type of the file
|
||||||
|
if path.as_ref().exists() {
|
||||||
|
show!(USimpleError::new(1, "no file systems processed"));
|
||||||
|
} else {
|
||||||
|
show!(USimpleError::new(
|
||||||
1,
|
1,
|
||||||
format!("{}: No such file or directory", path.as_ref().display())
|
format!("{}: No such file or directory", path.as_ref().display())
|
||||||
)),
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
|
@ -370,7 +384,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
}
|
}
|
||||||
Some(paths) => {
|
Some(paths) => {
|
||||||
let paths: Vec<&str> = paths.collect();
|
let paths: Vec<&str> = paths.collect();
|
||||||
let filesystems = get_named_filesystems(&paths);
|
let filesystems = get_named_filesystems(&paths, &opt);
|
||||||
|
|
||||||
// This can happen if paths are given as command-line arguments
|
// This can happen if paths are given as command-line arguments
|
||||||
// but none of the paths exist.
|
// but none of the paths exist.
|
||||||
|
@ -382,12 +396,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// This can happen if paths are given as command-line arguments
|
|
||||||
// but none of the paths exist.
|
|
||||||
if filesystems.is_empty() {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("{}", Table::new(&opt, filesystems));
|
println!("{}", Table::new(&opt, filesystems));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -199,7 +199,42 @@ fn test_type_option() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-t", fs_type, "-t", "nonexisting"])
|
.args(&["-t", fs_type, "-t", "nonexisting"])
|
||||||
.succeeds();
|
.succeeds();
|
||||||
new_ucmd!().args(&["-t", "nonexisting"]).fails();
|
new_ucmd!()
|
||||||
|
.args(&["-t", "nonexisting"])
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("no file systems processed");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_type_option_with_file() {
|
||||||
|
let fs_type = new_ucmd!()
|
||||||
|
.args(&["--output=fstype", "."])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_move_str();
|
||||||
|
let fs_type = fs_type.lines().nth(1).unwrap().trim();
|
||||||
|
|
||||||
|
new_ucmd!().args(&["-t", fs_type, "."]).succeeds();
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-t", "nonexisting", "."])
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("no file systems processed");
|
||||||
|
|
||||||
|
let fs_types = new_ucmd!()
|
||||||
|
.arg("--output=fstype")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_move_str();
|
||||||
|
let fs_types: Vec<_> = fs_types
|
||||||
|
.lines()
|
||||||
|
.skip(1)
|
||||||
|
.filter(|t| t.trim() != fs_type && t.trim() != "")
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if !fs_types.is_empty() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-t", fs_types[0], "."])
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("no file systems processed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue