1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

Merge branch 'main' into tail_notify

This commit is contained in:
Jan Scheer 2022-04-21 23:55:54 +02:00
commit 6c096267bf
No known key found for this signature in database
GPG key ID: C62AD4C29E2B9828
8 changed files with 87 additions and 20 deletions

31
Cargo.lock generated
View file

@ -604,9 +604,9 @@ dependencies = [
[[package]]
name = "crossterm"
version = "0.23.1"
version = "0.23.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1fd7173631a4e9e2ca8b32ae2fad58aab9843ea5aaf56642661937d87e28a3e"
checksum = "a2102ea4f781910f8a5b98dd061f4c2023f479ce7bb1236330099ceb5a93cf17"
dependencies = [
"bitflags",
"crossterm_winapi",
@ -1165,14 +1165,15 @@ dependencies = [
[[package]]
name = "mio"
version = "0.7.14"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc"
checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9"
dependencies = [
"libc",
"log",
"miow",
"ntapi",
"wasi 0.11.0+wasi-snapshot-preview1",
"winapi 0.3.9",
]
@ -1682,6 +1683,19 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "remove_dir_all"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "882f368737489ea543bc5c340e6f3d34a28c39980bd9a979e47322b26f60ac40"
dependencies = [
"libc",
"log",
"num_cpus",
"rayon",
"winapi 0.3.9",
]
[[package]]
name = "retain_mut"
version = "0.1.2"
@ -1810,9 +1824,9 @@ dependencies = [
[[package]]
name = "signal-hook-mio"
version = "0.2.1"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29fd5867f1c4f2c5be079aee7a2adf1152ebb04a4bc4d341f504b7dece607ed4"
checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af"
dependencies = [
"libc",
"mio 0.7.14",
@ -1920,7 +1934,7 @@ dependencies = [
"fastrand",
"libc",
"redox_syscall",
"remove_dir_all",
"remove_dir_all 0.5.3",
"winapi 0.3.9",
]
@ -2287,6 +2301,7 @@ version = "0.0.13"
dependencies = [
"clap 3.1.8",
"number_prefix",
"unicode-width",
"uucore",
]
@ -2754,7 +2769,7 @@ name = "uu_rm"
version = "0.0.13"
dependencies = [
"clap 3.1.8",
"remove_dir_all",
"remove_dir_all 0.7.0",
"uucore",
"walkdir",
"winapi 0.3.9",

View file

@ -52,8 +52,6 @@ Both can also be generated locally, the instructions for that can be found in th
uutils follows Rust's release channels and is tested against stable, beta and nightly.
The current oldest supported version of the Rust compiler is `1.56`.
On both Windows and Redox, only the nightly version is tested currently.
## Building
There are currently two methods to build the uutils binaries: either Cargo

View file

@ -61,6 +61,8 @@ highlight = "all"
# introduces it.
# spell-checker: disable
skip = [
# getrandom
{ name = "wasi", version="0.10.2+wasi-snapshot-preview1" },
# blake2d_simd
{ name = "arrayvec", version = "=0.7.2" },
# flimit/unix_socket
@ -76,6 +78,8 @@ skip = [
{ name = "cpp_common", version = "=0.4.0" },
# quickcheck
{ name = "env_logger", version = "=0.8.4" },
# tempfile
{ name = "remove_dir_all", version = "=0.5.3" },
# cpp_*
{ name = "memchr", version = "=1.0.2" },
{ name = "quote", version = "=0.3.15" },

View file

@ -18,6 +18,7 @@ path = "src/df.rs"
clap = { version = "3.1", features = ["wrap_help", "cargo"] }
number_prefix = "0.4"
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["libc", "fsext"] }
unicode-width = "0.1.9"
[[bin]]
name = "df"

View file

@ -287,6 +287,7 @@ fn get_all_filesystems(opt: &Options) -> Vec<Filesystem> {
mounts
.into_iter()
.filter_map(|m| Filesystem::new(m, None))
.filter(|fs| opt.show_all_fs || fs.usage.blocks > 0)
.collect()
}
@ -362,7 +363,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let filesystems = get_all_filesystems(&opt);
if filesystems.is_empty() {
return Err(USimpleError::new(1, "No file systems processed"));
return Err(USimpleError::new(1, "no file systems processed"));
}
filesystems

View file

@ -8,6 +8,7 @@
//! A table ([`Table`]) comprises a header row ([`Header`]) and a
//! collection of data rows ([`Row`]), one per filesystem.
use number_prefix::NumberPrefix;
use unicode_width::UnicodeWidthStr;
use crate::columns::{Alignment, Column};
use crate::filesystem::Filesystem;
@ -362,8 +363,8 @@ impl Table {
total += row;
for (i, value) in values.iter().enumerate() {
if value.len() > widths[i] {
widths[i] = value.len();
if UnicodeWidthStr::width(value.as_str()) > widths[i] {
widths[i] = UnicodeWidthStr::width(value.as_str());
}
}
@ -400,12 +401,21 @@ impl fmt::Display for Table {
while let Some(row) = row_iter.next() {
let mut col_iter = row.iter().enumerate().peekable();
while let Some((i, elem)) = col_iter.next() {
let is_last_col = col_iter.peek().is_none();
match self.alignments[i] {
Alignment::Left => write!(f, "{:<width$}", elem, width = self.widths[i])?,
Alignment::Left => {
if is_last_col {
// no trailing spaces in last column
write!(f, "{}", elem)?;
} else {
write!(f, "{:<width$}", elem, width = self.widths[i])?;
}
}
Alignment::Right => write!(f, "{:>width$}", elem, width = self.widths[i])?,
}
if col_iter.peek().is_some() {
if !is_last_col {
// column separator
write!(f, " ")?;
}

View file

@ -17,7 +17,7 @@ path = "src/rm.rs"
[dependencies]
clap = { version = "3.1", features = ["wrap_help", "cargo"] }
walkdir = "2.2"
remove_dir_all = "0.5.1"
remove_dir_all = "0.7.0"
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["fs"] }
[target.'cfg(windows)'.dependencies]

View file

@ -1,4 +1,6 @@
// spell-checker:ignore udev pcent iuse itotal iused ipcent
use std::collections::HashSet;
use crate::common::util::*;
#[test]
@ -165,6 +167,7 @@ fn test_output_mp_repeat() {
assert_eq!(3, output1.len());
assert_eq!(output1[1], output1[2]);
}
#[test]
fn test_output_conflict_options() {
for option in ["-i", "-T", "-P"] {
@ -204,6 +207,27 @@ fn test_exclude_type_option() {
new_ucmd!().args(&["-x", "ext4", "-x", "ext3"]).succeeds();
}
#[test]
fn test_exclude_all_types() {
let fs_types = new_ucmd!()
.arg("--output=fstype")
.succeeds()
.stdout_move_str();
let fs_types: HashSet<_> = fs_types.lines().skip(1).collect();
let mut args = Vec::new();
for fs_type in fs_types {
args.push("-x");
args.push(fs_type.trim_end());
}
new_ucmd!()
.args(&args)
.fails()
.stderr_contains("no file systems processed");
}
#[test]
fn test_include_exclude_same_type() {
new_ucmd!()
@ -349,7 +373,7 @@ fn test_output_selects_columns() {
.args(&["--output=source"])
.succeeds()
.stdout_move_str();
assert_eq!(output.lines().next().unwrap().trim_end(), "Filesystem");
assert_eq!(output.lines().next().unwrap(), "Filesystem");
let output = new_ucmd!()
.args(&["--output=source,target"])
@ -430,6 +454,20 @@ fn test_output_file_specific_files() {
assert_eq!(actual, vec!["File", "a", "b", "c"]);
}
#[test]
fn test_file_column_width_if_filename_contains_unicode_chars() {
let (at, mut ucmd) = at_and_ucmd!();
at.touch("äöü.txt");
let output = ucmd
.args(&["--output=file,target", "äöü.txt"])
.succeeds()
.stdout_move_str();
let actual = output.lines().next().unwrap();
// expected width: 7 chars (length of äöü.txt) + 1 char (column separator)
assert_eq!(actual, "File Mounted on");
}
#[test]
fn test_output_field_no_more_than_once() {
new_ucmd!()