From 46fc91af19d756bca02d460455d685d5a66b801b Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Fri, 10 Sep 2021 18:36:51 +0200 Subject: [PATCH 01/21] test_ls: add features for uutils called by ccmd --- tests/by-util/test_ls.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 3d6092416..01c60e3fd 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -371,6 +371,7 @@ fn test_ls_long_format() { /// and `.` and `..` being present in `-a` all need to work for the test to pass. /// This test does not really test anything provided by `-l` but the file names and symlinks. #[test] +#[cfg(all(feature = "ln", feature = "mkdir", feature = "touch"))] fn test_ls_long_symlink_color() { // If you break this test after breaking mkdir, touch, or ln, do not be alarmed! // This test is made for ls, but it attempts to run those utils in the process. From 96b8616a1a328915b7e3b1e14fbf7fd5961d7318 Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Thu, 9 Sep 2021 22:02:31 -0400 Subject: [PATCH 02/21] seq: use stdout.write_all() instead of print!() Change from using `print!()` to using `stdout.write_all()` in order to allow the main function to handle broken pipe errors gracefully. --- src/uu/seq/src/seq.rs | 40 ++++++++++++++++++++++++--------------- tests/by-util/test_seq.rs | 24 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 501b12ac0..493b0c589 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -12,7 +12,7 @@ use num_traits::One; use num_traits::Zero; use num_traits::{Num, ToPrimitive}; use std::cmp; -use std::io::{stdout, Write}; +use std::io::{stdout, ErrorKind, Write}; use std::str::FromStr; use uucore::display::Quotable; @@ -192,7 +192,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .num_digits() .max(increment.num_digits()) .max(last.num_digits()); - match (first, last, increment) { + let result = match (first, last, increment) { (Number::MinusZero, Number::BigInt(last), Number::BigInt(increment)) => print_seq_integers( (BigInt::zero(), increment, last), options.separator, @@ -219,8 +219,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 { options.widths, padding, ), + }; + match result { + Ok(_) => 0, + Err(err) if err.kind() == ErrorKind::BrokenPipe => 0, + Err(_) => 1, } - 0 } pub fn uu_app() -> App<'static, 'static> { @@ -276,7 +280,9 @@ fn print_seq( terminator: String, pad: bool, padding: usize, -) { +) -> std::io::Result<()> { + let stdout = stdout(); + let mut stdout = stdout.lock(); let (first, increment, last) = range; let mut i = 0isize; let mut value = first + i as f64 * increment; @@ -286,20 +292,21 @@ fn print_seq( let before_dec = istr.find('.').unwrap_or(ilen); if pad && before_dec < padding { for _ in 0..(padding - before_dec) { - print!("0"); + write!(stdout, "0")?; } } - print!("{}", istr); + write!(stdout, "{}", istr)?; i += 1; value = first + i as f64 * increment; if !done_printing(&value, &increment, &last) { - print!("{}", separator); + write!(stdout, "{}", separator)?; } } if (first >= last && increment < 0f64) || (first <= last && increment > 0f64) { - print!("{}", terminator); + write!(stdout, "{}", terminator)?; } - crash_if_err!(1, stdout().flush()); + stdout.flush()?; + Ok(()) } /// Print an integer sequence. @@ -323,31 +330,34 @@ fn print_seq_integers( pad: bool, padding: usize, is_first_minus_zero: bool, -) { +) -> std::io::Result<()> { + let stdout = stdout(); + let mut stdout = stdout.lock(); let (first, increment, last) = range; let mut value = first; let mut is_first_iteration = true; while !done_printing(&value, &increment, &last) { if !is_first_iteration { - print!("{}", separator); + write!(stdout, "{}", separator)?; } let mut width = padding; if is_first_iteration && is_first_minus_zero { - print!("-"); + write!(stdout, "-")?; width -= 1; } is_first_iteration = false; if pad { - print!("{number:>0width$}", number = value, width = width); + write!(stdout, "{number:>0width$}", number = value, width = width)?; } else { - print!("{}", value); + write!(stdout, "{}", value)?; } value += &increment; } if !is_first_iteration { - print!("{}", terminator); + write!(stdout, "{}", terminator)?; } + Ok(()) } #[cfg(test)] diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index 458769839..4325c7fba 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -1,4 +1,5 @@ use crate::common::util::*; +use std::io::Read; #[test] fn test_rejects_nan() { @@ -176,3 +177,26 @@ fn test_width_negative_zero() { .stdout_is("-0\n01\n") .no_stderr(); } + +// TODO This is duplicated from `test_yes.rs`; refactor them. +/// Run `seq`, capture some of the output, close the pipe, and verify it. +fn run(args: &[&str], expected: &[u8]) { + let mut cmd = new_ucmd!(); + let mut child = cmd.args(args).run_no_wait(); + let mut stdout = child.stdout.take().unwrap(); + let mut buf = vec![0; expected.len()]; + stdout.read_exact(&mut buf).unwrap(); + drop(stdout); + assert!(child.wait().unwrap().success()); + assert_eq!(buf.as_slice(), expected); +} + +#[test] +fn test_neg_inf() { + run(&["--", "-inf", "0"], b"-inf\n-inf\n-inf\n"); +} + +#[test] +fn test_inf() { + run(&["inf"], b"1\n2\n3\n"); +} From 664c7a6ec5a12a999af949f4ed1f93227ead5b6f Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Sun, 1 Aug 2021 11:19:44 -0400 Subject: [PATCH 03/21] tac: add support for --regex option to tac Add support for `tac --regex`, where the line separator is interpreted as a regular expression. --- Cargo.lock | 1 + src/uu/tac/Cargo.toml | 1 + src/uu/tac/src/tac.rs | 90 ++++++++++++++++++++++++++++++++++++--- tests/by-util/test_tac.rs | 66 +++++++++++++++++++++++++++- 4 files changed, 152 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 808f62e15..f8de8d4a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3051,6 +3051,7 @@ version = "0.0.7" dependencies = [ "clap", "memchr 2.4.0", + "regex", "uucore", "uucore_procs", ] diff --git a/src/uu/tac/Cargo.toml b/src/uu/tac/Cargo.toml index 3ba1497a0..4a91786aa 100644 --- a/src/uu/tac/Cargo.toml +++ b/src/uu/tac/Cargo.toml @@ -16,6 +16,7 @@ path = "src/tac.rs" [dependencies] memchr = "2" +regex = "1" clap = { version = "2.33", features = ["wrap_help"] } uucore = { version=">=0.0.9", package="uucore", path="../../uucore" } uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_procs" } diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index e54697f2b..4a93a7c65 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -69,7 +69,7 @@ pub fn uu_app() -> App<'static, 'static> { Arg::with_name(options::REGEX) .short("r") .long(options::REGEX) - .help("interpret the sequence as a regular expression (NOT IMPLEMENTED)") + .help("interpret the sequence as a regular expression") .takes_value(false), ) .arg( @@ -82,6 +82,82 @@ pub fn uu_app() -> App<'static, 'static> { .arg(Arg::with_name(options::FILE).hidden(true).multiple(true)) } +/// Print lines of a buffer in reverse, with line separator given as a regex. +/// +/// `data` contains the bytes of the file. +/// +/// `pattern` is the regular expression given as a +/// [`regex::bytes::Regex`] (not a [`regex::Regex`], since the input is +/// given as a slice of bytes). If `before` is `true`, then each match +/// of this pattern in `data` is interpreted as the start of a line. If +/// `before` is `false`, then each match of this pattern is interpreted +/// as the end of a line. +/// +/// This function writes each line in `data` to [`std::io::Stdout`] in +/// reverse. +/// +/// # Errors +/// +/// If there is a problem writing to `stdout`, then this function +/// returns [`std::io::Error`]. +fn buffer_tac_regex( + data: &[u8], + pattern: regex::bytes::Regex, + before: bool, +) -> std::io::Result<()> { + let mut out = stdout(); + + // The index of the line separator for the current line. + // + // As we scan through the `data` from right to left, we update this + // variable each time we find a new line separator. We restrict our + // regular expression search to only those bytes up to the line + // separator. + let mut this_line_end = data.len(); + + // The index of the start of the next line in the `data`. + // + // As we scan through the `data` from right to left, we update this + // variable each time we find a new line. + // + // If `before` is `true`, then each line starts immediately before + // the line separator. Otherwise, each line starts immediately after + // the line separator. + let mut following_line_start = data.len(); + + // Iterate over each byte in the buffer in reverse. When we find a + // line separator, write the line to stdout. + // + // The `before` flag controls whether the line separator appears at + // the end of the line (as in "abc\ndef\n") or at the beginning of + // the line (as in "/abc/def"). + for i in (0..data.len()).rev() { + // Determine if there is a match for `pattern` starting at index + // `i` in `data`. Only search up to the line ending that was + // found previously. + if let Some(match_) = pattern.find_at(&data[..this_line_end], i) { + // Record this index as the ending of the current line. + this_line_end = i; + + // The length of the match (that is, the line separator), in bytes. + let slen = match_.end() - match_.start(); + + if before { + out.write_all(&data[i..following_line_start])?; + following_line_start = i; + } else { + out.write_all(&data[i + slen..following_line_start])?; + following_line_start = i + slen; + } + } + } + + // After the loop terminates, write whatever bytes are remaining at + // the beginning of the buffer. + out.write_all(&data[0..following_line_start])?; + Ok(()) +} + /// Write lines from `data` to stdout in reverse. /// /// This function writes to [`stdout`] each line appearing in `data`, @@ -132,7 +208,7 @@ fn buffer_tac(data: &[u8], before: bool, separator: &str) -> std::io::Result<()> Ok(()) } -fn tac(filenames: Vec, before: bool, _: bool, separator: &str) -> i32 { +fn tac(filenames: Vec, before: bool, regex: bool, separator: &str) -> i32 { let mut exit_code = 0; for filename in &filenames { @@ -168,9 +244,13 @@ fn tac(filenames: Vec, before: bool, _: bool, separator: &str) -> i32 { exit_code = 1; continue; }; - - buffer_tac(&data, before, separator) - .unwrap_or_else(|e| crash!(1, "failed to write to stdout: {}", e)); + if regex { + let pattern = crash_if_err!(1, regex::bytes::Regex::new(separator)); + buffer_tac_regex(&data, pattern, before) + } else { + buffer_tac(&data, before, separator) + } + .unwrap_or_else(|e| crash!(1, "failed to write to stdout: {}", e)); } exit_code } diff --git a/tests/by-util/test_tac.rs b/tests/by-util/test_tac.rs index 202f76d66..323aa5149 100644 --- a/tests/by-util/test_tac.rs +++ b/tests/by-util/test_tac.rs @@ -1,4 +1,4 @@ -// spell-checker:ignore axxbxx bxxaxx axxx axxxx xxaxx xxax xxxxa +// spell-checker:ignore axxbxx bxxaxx axxx axxxx xxaxx xxax xxxxa axyz zyax zyxa use crate::common::util::*; #[test] @@ -205,3 +205,67 @@ fn test_null_separator() { .succeeds() .stdout_is("b\0a\0"); } + +#[test] +fn test_regex() { + new_ucmd!() + .args(&["-r", "-s", "[xyz]+"]) + .pipe_in("axyz") + .succeeds() + .no_stderr() + .stdout_is("zyax"); + + new_ucmd!() + .args(&["-r", "-s", ":+"]) + .pipe_in("a:b::c:::d::::") + .succeeds() + .no_stderr() + .stdout_is(":::d:::c::b:a:"); + + new_ucmd!() + .args(&["-r", "-s", r"[\+]+[-]+[\+]+"]) + // line 0 1 2 + // |--||-----||--------| + .pipe_in("a+-+b++--++c+d-e+---+") + .succeeds() + .no_stderr() + // line 2 1 0 + // |--------||-----||--| + .stdout_is("c+d-e+---+b++--++a+-+"); +} + +#[test] +fn test_regex_before() { + new_ucmd!() + .args(&["-b", "-r", "-s", "[xyz]+"]) + .pipe_in("axyz") + .succeeds() + .no_stderr() + .stdout_is("zyxa"); + + new_ucmd!() + .args(&["-b", "-r", "-s", ":+"]) + .pipe_in(":a::b:::c::::d") + .succeeds() + .stdout_is(":d::::c:::b::a"); + + // Because `tac` searches for matches of the regular expression from + // right to left, the second to last line is + // + // +--++b + // + // not + // + // ++--++b + // + new_ucmd!() + .args(&["-b", "-r", "-s", r"[\+]+[-]+[\+]+"]) + // line 0 1 2 + // |---||----||--------| + .pipe_in("+-+a++--++b+---+c+d-e") + .succeeds() + .no_stderr() + // line 2 1 0 + // |--------||----||---| + .stdout_is("+---+c+d-e+--++b+-+a+"); +} From cc8522a2db080d6f2c3fb617db4f872e6f2137c4 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 12 Sep 2021 23:14:34 +0200 Subject: [PATCH 04/21] Fixed a warning on freebdsd: warning: unused import: `std::os::unix::fs::PermissionsExt` --- tests/by-util/test_cp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index f126517fe..e86f35833 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -9,7 +9,7 @@ use std::os::unix::fs; #[cfg(unix)] use std::os::unix::fs::symlink as symlink_file; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "freebsd")))] use std::os::unix::fs::PermissionsExt; #[cfg(windows)] use std::os::windows::fs::symlink_file; From deedb73bcbe2b9454bdb0c97572d8ddf53bf9708 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Mon, 13 Sep 2021 12:12:32 +0200 Subject: [PATCH 05/21] tests/common: make call to `host_name_for` idempotent This fixes an issue on macOS/bsd where multiple calls to `host_name_for` each added a prefix 'g'. The issue led to some tests being skipped because `util_name` was renamed to e.g. "ggid" instead of "gid". --- tests/common/util.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 5441b82c2..47d6a8850 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -1081,7 +1081,14 @@ pub fn host_name_for(util_name: &str) -> Cow { // In some environments, e.g. macOS/freebsd, the GNU coreutils are prefixed with "g" // to not interfere with the BSD counterparts already in `$PATH`. #[cfg(not(target_os = "linux"))] - return format!("g{}", util_name).into(); + { + // make call to `host_name_for` idempotent + if util_name.starts_with('g') && util_name != "groups" { + return util_name.into(); + } else { + return format!("g{}", util_name).into(); + } + } #[cfg(target_os = "linux")] return util_name.into(); } @@ -1195,8 +1202,8 @@ pub fn check_coreutil_version( ///``` #[cfg(unix)] pub fn expected_result(ts: &TestScenario, args: &[&str]) -> std::result::Result { + println!("{}", check_coreutil_version(&ts.util_name, VERSION_MIN)?); let util_name = &host_name_for(&ts.util_name); - println!("{}", check_coreutil_version(util_name, VERSION_MIN)?); let result = ts .cmd_keepenv(util_name.as_ref()) @@ -1493,4 +1500,25 @@ mod tests { let ts = TestScenario::new("no test name"); assert!(expected_result(&ts, &[]).is_err()); } + + #[test] + #[cfg(unix)] + fn test_host_name_for() { + #[cfg(target_os = "linux")] + { + std::assert_eq!(host_name_for("id"), "id"); + std::assert_eq!(host_name_for("groups"), "groups"); + std::assert_eq!(host_name_for("who"), "who"); + } + #[cfg(not(target_os = "linux"))] + { + // spell-checker:ignore (strings) ggroups gwho + std::assert_eq!(host_name_for("id"), "gid"); + std::assert_eq!(host_name_for("groups"), "ggroups"); + std::assert_eq!(host_name_for("who"), "gwho"); + std::assert_eq!(host_name_for("gid"), "gid"); + std::assert_eq!(host_name_for("ggroups"), "ggroups"); + std::assert_eq!(host_name_for("gwho"), "gwho"); + } + } } From 450a3faf9fa5edf061e327acf25647cf85692616 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 13 Sep 2021 12:29:28 +0200 Subject: [PATCH 06/21] Add to the spell ignore list --- tests/common/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 47d6a8850..704e9b163 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -3,7 +3,7 @@ // * For the full copyright and license information, please view the LICENSE // * file that was distributed with this source code. -//spell-checker: ignore (linux) rlimit prlimit Rlim coreutil +//spell-checker: ignore (linux) rlimit prlimit Rlim coreutil ggroups #![allow(dead_code)] From ebe897e4d426b171763e587d92774e2118a2aabd Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 13 Sep 2021 18:05:06 +0200 Subject: [PATCH 07/21] shred: remove unused "time" dep (#2665) --- Cargo.lock | 1 - src/uu/shred/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf710ea00..be0f3adf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2941,7 +2941,6 @@ dependencies = [ "filetime", "libc", "rand 0.7.3", - "time", "uucore", "uucore_procs", ] diff --git a/src/uu/shred/Cargo.toml b/src/uu/shred/Cargo.toml index f515044c0..d6bb61c76 100644 --- a/src/uu/shred/Cargo.toml +++ b/src/uu/shred/Cargo.toml @@ -19,7 +19,6 @@ clap = { version = "2.33", features = ["wrap_help"] } filetime = "0.2.1" libc = "0.2.42" rand = "0.7" -time = "0.1.40" uucore = { version=">=0.0.9", package="uucore", path="../../uucore" } uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_procs" } From 68df4de1a21972c7c49c85e7a11bf6ed33e3a190 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 13 Sep 2021 18:08:41 +0200 Subject: [PATCH 08/21] nice: update to use the same version of nix as other programs (#2666) --- Cargo.lock | 21 +-------------------- src/uu/nice/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be0f3adf2..a46207e5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1104,19 +1104,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "nix" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dbdc256eaac2e3bd236d93ad999d3479ef775c863dbda3068c4006a92eec51b" -dependencies = [ - "bitflags", - "cc", - "cfg-if 0.1.10", - "libc", - "void", -] - [[package]] name = "nix" version = "0.19.1" @@ -2712,7 +2699,7 @@ version = "0.0.7" dependencies = [ "clap", "libc", - "nix 0.13.1", + "nix 0.20.0", "uucore", "uucore_procs", ] @@ -3312,12 +3299,6 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" - [[package]] name = "walkdir" version = "2.3.2" diff --git a/src/uu/nice/Cargo.toml b/src/uu/nice/Cargo.toml index 31c310790..5f0c2c07a 100644 --- a/src/uu/nice/Cargo.toml +++ b/src/uu/nice/Cargo.toml @@ -17,7 +17,7 @@ path = "src/nice.rs" [dependencies] clap = { version = "2.33", features = ["wrap_help"] } libc = "0.2.42" -nix = { version="<=0.13" } +nix = "0.20" uucore = { version=">=0.0.9", package="uucore", path="../../uucore" } uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_procs" } From 87b6aa89e38a1b0947700f763db2e400cc031e40 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 13 Sep 2021 18:08:51 +0200 Subject: [PATCH 09/21] pr: remove unused "time" dep (#2667) --- Cargo.lock | 1 - src/uu/pr/Cargo.toml | 2 -- 2 files changed, 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a46207e5f..8759a133d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2799,7 +2799,6 @@ dependencies = [ "itertools 0.10.1", "quick-error 2.0.1", "regex", - "time", "uucore", "uucore_procs", ] diff --git a/src/uu/pr/Cargo.toml b/src/uu/pr/Cargo.toml index d446e66a0..fd46e817e 100644 --- a/src/uu/pr/Cargo.toml +++ b/src/uu/pr/Cargo.toml @@ -19,8 +19,6 @@ clap = { version = "2.33", features = ["wrap_help"] } uucore = { version=">=0.0.7", package="uucore", path="../../uucore", features=["entries"] } uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_procs" } getopts = "0.2.21" -time = "0.1.41" -# A higher version would cause a conflict with time chrono = "0.4.19" quick-error = "2.0.1" itertools = "0.10" From cca2b19b4e6c892a963e94d6c7b28211fe17d9d9 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 12 Sep 2021 22:23:12 +0200 Subject: [PATCH 10/21] tail: only set the winapi dep on Windows --- src/uu/tail/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/uu/tail/Cargo.toml b/src/uu/tail/Cargo.toml index 6928330de..0fe84670e 100644 --- a/src/uu/tail/Cargo.toml +++ b/src/uu/tail/Cargo.toml @@ -19,6 +19,8 @@ clap = { version = "2.33", features = ["wrap_help"] } libc = "0.2.42" uucore = { version=">=0.0.9", package="uucore", path="../../uucore", features=["ringbuffer"] } uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_procs" } + +[target.'cfg(windows)'.dependencies] winapi = { version="0.3", features=["fileapi", "handleapi", "processthreadsapi", "synchapi", "winbase"] } [target.'cfg(target_os = "redox")'.dependencies] From 2d67252dc4c2d282d8f311681fdc0be4fee13260 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 12 Sep 2021 19:20:30 +0200 Subject: [PATCH 11/21] rm: only set the winapi dep on Windows --- src/uu/rm/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/rm/Cargo.toml b/src/uu/rm/Cargo.toml index 2c30446e8..c356f03e4 100644 --- a/src/uu/rm/Cargo.toml +++ b/src/uu/rm/Cargo.toml @@ -18,11 +18,11 @@ path = "src/rm.rs" clap = { version = "2.33", features = ["wrap_help"] } walkdir = "2.2" remove_dir_all = "0.5.1" -winapi = { version="0.3", features=[] } - uucore = { version=">=0.0.9", package="uucore", path="../../uucore", features=["fs"] } uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_procs" } +[target.'cfg(windows)'.dependencies] +winapi = { version="0.3", features=[] } [[bin]] name = "rm" From 826c948234ab903e0df731761703b8fbcadeab0a Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 12 Sep 2021 19:21:40 +0200 Subject: [PATCH 12/21] ls: remove the unused dep on locale --- Cargo.lock | 10 ---------- src/uu/ls/Cargo.toml | 1 - 2 files changed, 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8759a133d..56464ef98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1004,15 +1004,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "locale" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fdbe492a9c0238da900a1165c42fc5067161ce292678a6fe80921f30fe307fd" -dependencies = [ - "libc", -] - [[package]] name = "lock_api" version = "0.4.4" @@ -2615,7 +2606,6 @@ dependencies = [ "clap", "globset", "lazy_static", - "locale", "lscolors", "number_prefix", "once_cell", diff --git a/src/uu/ls/Cargo.toml b/src/uu/ls/Cargo.toml index dbe6bacaa..6c4858a1c 100644 --- a/src/uu/ls/Cargo.toml +++ b/src/uu/ls/Cargo.toml @@ -15,7 +15,6 @@ edition = "2018" path = "src/ls.rs" [dependencies] -locale = "0.2.2" chrono = "0.4.19" clap = { version = "2.33", features = ["wrap_help"] } unicode-width = "0.1.8" From a6c235bcd10864db63b16556c45c74aa172ad4b0 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 12 Sep 2021 19:22:22 +0200 Subject: [PATCH 13/21] csplit: remove the unused dep on glob --- Cargo.lock | 1 - src/uu/csplit/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56464ef98..b4c8aa9b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2292,7 +2292,6 @@ name = "uu_csplit" version = "0.0.7" dependencies = [ "clap", - "glob", "regex", "thiserror", "uucore", diff --git a/src/uu/csplit/Cargo.toml b/src/uu/csplit/Cargo.toml index 82389a93b..3bc44b90c 100644 --- a/src/uu/csplit/Cargo.toml +++ b/src/uu/csplit/Cargo.toml @@ -18,7 +18,6 @@ path = "src/csplit.rs" clap = { version = "2.33", features = ["wrap_help"] } thiserror = "1.0" regex = "1.0.0" -glob = "0.3" uucore = { version=">=0.0.9", package="uucore", path="../../uucore", features=["entries", "fs"] } uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_procs" } From a74e4bf09599d1fd8dfd16190b6317055052c52e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 12 Sep 2021 19:59:54 +0200 Subject: [PATCH 14/21] shred: remove the unused dep on filetime --- Cargo.lock | 1 - src/uu/shred/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4c8aa9b1..eb2c709ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2913,7 +2913,6 @@ name = "uu_shred" version = "0.0.7" dependencies = [ "clap", - "filetime", "libc", "rand 0.7.3", "uucore", diff --git a/src/uu/shred/Cargo.toml b/src/uu/shred/Cargo.toml index d6bb61c76..5f7bebb4e 100644 --- a/src/uu/shred/Cargo.toml +++ b/src/uu/shred/Cargo.toml @@ -16,7 +16,6 @@ path = "src/shred.rs" [dependencies] clap = { version = "2.33", features = ["wrap_help"] } -filetime = "0.2.1" libc = "0.2.42" rand = "0.7" uucore = { version=">=0.0.9", package="uucore", path="../../uucore" } From 2a4422997d4e2565875e629b79d5bfe077b257ac Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 13 Sep 2021 20:09:13 +0200 Subject: [PATCH 15/21] Restrict some crates to specific OS --- Cargo.toml | 7 +++++-- src/uucore/Cargo.toml | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 58b6aa52a..7b1399abf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -366,7 +366,6 @@ conv = "0.3" filetime = "0.2" glob = "0.3.0" libc = "0.2" -nix = "0.20.0" pretty_assertions = "0.7.2" rand = "0.7" regex = "1.0" @@ -378,8 +377,12 @@ uucore = { version=">=0.0.9", package="uucore", path="src/uucore", features=["en walkdir = "2.2" atty = "0.2" -[target.'cfg(unix)'.dev-dependencies] +[target.'cfg(target_os = "linux")'.dev-dependencies] rlimit = "0.4.0" + +[target.'cfg(unix)'.dev-dependencies] +nix = "0.20.0" + rust-users = { version="0.10", package="users" } unix_socket = "0.5.0" diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index 80a3a115b..3f2276bd3 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -24,13 +24,15 @@ wild = "2.0" # * optional thiserror = { version="1.0", optional=true } time = { version="<= 0.1.43", optional=true } -walkdir = { version="2.3.2", optional=true } # * "problem" dependencies (pinned) data-encoding = { version="2.1", optional=true } data-encoding-macro = { version="0.1.12", optional=true } z85 = { version="3.0.3", optional=true } libc = { version="0.2.15", optional=true } once_cell = "1.8.0" + +[target.'cfg(unix)'.dependencies] +walkdir = { version="2.3.2", optional=true } nix = { version="0.20", optional=true } [dev-dependencies] From 60025800c3cd7a1d43c23e2423c3b81110a2e30e Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Sat, 11 Sep 2021 23:10:13 -0400 Subject: [PATCH 16/21] seq: trim leading whitespace from inputs --- src/uu/seq/src/seq.rs | 1 + tests/by-util/test_seq.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 493b0c589..8aef226b5 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -99,6 +99,7 @@ impl Number { impl FromStr for Number { type Err = String; fn from_str(mut s: &str) -> Result { + s = s.trim_start(); if s.starts_with('+') { s = &s[1..]; } diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index 4325c7fba..65f2451f0 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -200,3 +200,27 @@ fn test_neg_inf() { fn test_inf() { run(&["inf"], b"1\n2\n3\n"); } + +#[test] +fn test_ignore_leading_whitespace() { + new_ucmd!() + .arg(" 1") + .succeeds() + .stdout_is("1\n") + .no_stderr(); +} + +#[test] +fn test_trailing_whitespace_error() { + // In some locales, the GNU error message has curly quotes (‘) + // instead of straight quotes ('). We just test the straight single + // quotes. + new_ucmd!() + .arg("1 ") + .fails() + .no_stdout() + .stderr_contains("seq: invalid floating point argument: '1 '") + // FIXME The second line of the error message is "Try 'seq + // --help' for more information." + .stderr_contains("for more information."); +} From 1edd2bf3a89e5cf027bee026341d93d660a97cbb Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Tue, 14 Sep 2021 15:07:57 +0200 Subject: [PATCH 17/21] Do not discard non-OS error messages --- .../cspell.dictionaries/jargon.wordlist.txt | 3 + src/uu/install/src/install.rs | 9 +-- src/uu/ls/src/ls.rs | 11 ++- src/uucore/src/lib/mods/error.rs | 76 ++++++++++++------- 4 files changed, 64 insertions(+), 35 deletions(-) diff --git a/.vscode/cspell.dictionaries/jargon.wordlist.txt b/.vscode/cspell.dictionaries/jargon.wordlist.txt index cd1cc18b3..ed9e3d738 100644 --- a/.vscode/cspell.dictionaries/jargon.wordlist.txt +++ b/.vscode/cspell.dictionaries/jargon.wordlist.txt @@ -43,6 +43,9 @@ gibi gibibytes glob globbing +hardcode +hardcoded +hardcoding hardfloat hardlink hardlinks diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index a9f91f658..1c09f7f34 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -490,11 +490,10 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UR return Err(InstallError::TargetDirIsntDir(target_dir.to_path_buf()).into()); } for sourcepath in files.iter() { - if !sourcepath.exists() { - let err = UIoError::new( - std::io::ErrorKind::NotFound, - format!("cannot stat {}", sourcepath.quote()), - ); + if let Err(err) = sourcepath + .metadata() + .map_err_context(|| format!("cannot stat {}", sourcepath.quote())) + { show!(err); continue; } diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index fad30157c..c5c65334e 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -42,7 +42,7 @@ use std::{ use term_grid::{Cell, Direction, Filling, Grid, GridOptions}; use uucore::{ display::Quotable, - error::{set_exit_code, FromIo, UError, UResult}, + error::{set_exit_code, UError, UResult}, }; use unicode_width::UnicodeWidthStr; @@ -1257,8 +1257,13 @@ fn list(locs: Vec<&Path>, config: Config) -> UResult<()> { let path_data = PathData::new(p, None, None, &config, true); if path_data.md().is_none() { - show!(std::io::ErrorKind::NotFound - .map_err_context(|| format!("cannot access {}", path_data.p_buf.quote()))); + // FIXME: Would be nice to use the actual error instead of hardcoding it + // Presumably other errors can happen too? + show_error!( + "cannot access {}: No such file or directory", + path_data.p_buf.quote() + ); + set_exit_code(1); // We found an error, no need to continue the execution continue; } diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index 11ec91bdf..c04a0f2f1 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -393,34 +393,56 @@ impl Display for UIoError { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { use std::io::ErrorKind::*; - let message; - let message = match self.inner.kind() { - NotFound => "No such file or directory", - PermissionDenied => "Permission denied", - ConnectionRefused => "Connection refused", - ConnectionReset => "Connection reset", - ConnectionAborted => "Connection aborted", - NotConnected => "Not connected", - AddrInUse => "Address in use", - AddrNotAvailable => "Address not available", - BrokenPipe => "Broken pipe", - AlreadyExists => "Already exists", - WouldBlock => "Would block", - InvalidInput => "Invalid input", - InvalidData => "Invalid data", - TimedOut => "Timed out", - WriteZero => "Write zero", - Interrupted => "Interrupted", - UnexpectedEof => "Unexpected end of file", - _ => { - // TODO: using `strip_errno()` causes the error message - // to not be capitalized. When the new error variants (https://github.com/rust-lang/rust/issues/86442) - // are stabilized, we should add them to the match statement. - message = strip_errno(&self.inner); - &message + let mut message; + let message = if self.inner.raw_os_error().is_some() { + // These are errors that come directly from the OS. + // We want to normalize their messages across systems, + // and we want to strip the "(os error X)" suffix. + match self.inner.kind() { + NotFound => "No such file or directory", + PermissionDenied => "Permission denied", + ConnectionRefused => "Connection refused", + ConnectionReset => "Connection reset", + ConnectionAborted => "Connection aborted", + NotConnected => "Not connected", + AddrInUse => "Address in use", + AddrNotAvailable => "Address not available", + BrokenPipe => "Broken pipe", + AlreadyExists => "Already exists", + WouldBlock => "Would block", + InvalidInput => "Invalid input", + InvalidData => "Invalid data", + TimedOut => "Timed out", + WriteZero => "Write zero", + Interrupted => "Interrupted", + UnexpectedEof => "Unexpected end of file", + _ => { + // TODO: When the new error variants + // (https://github.com/rust-lang/rust/issues/86442) + // are stabilized, we should add them to the match statement. + message = strip_errno(&self.inner); + capitalize(&mut message); + &message + } } + } else { + // These messages don't need as much normalization, and the above + // messages wouldn't always be a good substitute. + // For example, ErrorKind::NotFound doesn't necessarily mean it was + // a file that was not found. + // There are also errors with entirely custom messages. + message = self.inner.to_string(); + capitalize(&mut message); + &message }; - write!(f, "{}: {}", self.context, message,) + write!(f, "{}: {}", self.context, message) + } +} + +/// Capitalize the first character of an ASCII string. +fn capitalize(text: &mut str) { + if let Some(first) = text.get_mut(..1) { + first.make_ascii_uppercase(); } } @@ -428,7 +450,7 @@ impl Display for UIoError { pub fn strip_errno(err: &std::io::Error) -> String { let mut msg = err.to_string(); if let Some(pos) = msg.find(" (os error ") { - msg.drain(pos..); + msg.truncate(pos); } msg } From 53a91be2dfe11a87c05c5de7d085e81291e8909d Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Tue, 14 Sep 2021 20:54:31 -0400 Subject: [PATCH 18/21] seq: add is_first_iteration to avoid comparisons Add the `is_first_iteration` Boolean variable to the `print_seq()` function in order to avoid unnecessary comparisons. Specifically, before this change, the `done_printing()` function was called twice on each iteration of the main loop. After this change, it is only called once per iteration. Furthermore, this change makes the `print_seq()` function similar in structure to the `print_seq_integers()` function. Co-authored-by: Jan Verbeek --- src/uu/seq/src/seq.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 8aef226b5..0cea90838 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -287,7 +287,12 @@ fn print_seq( let (first, increment, last) = range; let mut i = 0isize; let mut value = first + i as f64 * increment; + let mut is_first_iteration = true; while !done_printing(&value, &increment, &last) { + if !is_first_iteration { + write!(stdout, "{}", separator)?; + } + is_first_iteration = false; let istr = format!("{:.*}", largest_dec, value); let ilen = istr.len(); let before_dec = istr.find('.').unwrap_or(ilen); @@ -299,11 +304,8 @@ fn print_seq( write!(stdout, "{}", istr)?; i += 1; value = first + i as f64 * increment; - if !done_printing(&value, &increment, &last) { - write!(stdout, "{}", separator)?; - } } - if (first >= last && increment < 0f64) || (first <= last && increment > 0f64) { + if !is_first_iteration { write!(stdout, "{}", terminator)?; } stdout.flush()?; From f95ab2f43caee95fe05b9f28deabd28bb34c92b5 Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Tue, 14 Sep 2021 21:26:50 -0400 Subject: [PATCH 19/21] uucore(panic): guard against "Broken pipe" panics Add "Broken pipe" to the set of panic messages used to determine whether a panic is caused by a broken pipe error. --- src/uucore/src/lib/mods/panic.rs | 41 +++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/uucore/src/lib/mods/panic.rs b/src/uucore/src/lib/mods/panic.rs index ba0ecdf12..ebba10429 100644 --- a/src/uucore/src/lib/mods/panic.rs +++ b/src/uucore/src/lib/mods/panic.rs @@ -1,17 +1,42 @@ +//! Custom panic hooks that allow silencing certain types of errors. +//! +//! Use the [`mute_sigpipe_panic`] function to silence panics caused by +//! broken pipe errors. This can happen when a process is still +//! producing data when the consuming process terminates and closes the +//! pipe. For example, +//! +//! ```sh +//! $ seq inf | head -n 1 +//! ``` +//! use std::panic; +use std::panic::PanicInfo; -//## SIGPIPE handling background/discussions ... -//* `uutils` ~ , -//* rust and `rg` ~ , , +/// Decide whether a panic was caused by a broken pipe (SIGPIPE) error. +fn is_broken_pipe(info: &PanicInfo) -> bool { + if let Some(res) = info.payload().downcast_ref::() { + if res.contains("BrokenPipe") || res.contains("Broken pipe") { + return true; + } + } + false +} +/// Terminate without error on panics that occur due to broken pipe errors. +/// +/// For background discussions on `SIGPIPE` handling, see +/// +/// * https://github.com/uutils/coreutils/issues/374 +/// * https://github.com/uutils/coreutils/pull/1106 +/// * https://github.com/rust-lang/rust/issues/62569 +/// * https://github.com/BurntSushi/ripgrep/issues/200 +/// * https://github.com/crev-dev/cargo-crev/issues/287 +/// pub fn mute_sigpipe_panic() { let hook = panic::take_hook(); panic::set_hook(Box::new(move |info| { - if let Some(res) = info.payload().downcast_ref::() { - if res.contains("BrokenPipe") { - return; - } + if !is_broken_pipe(info) { + hook(info) } - hook(info) })); } From 7eaae75bfcd72b4022d88fbcfab9796f26a6c57d Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 12 Sep 2021 20:10:39 +0200 Subject: [PATCH 20/21] add a github action job to identify unused deps --- .github/workflows/CICD.yml | 32 +++++++++++++++++++ .../cspell.dictionaries/jargon.wordlist.txt | 1 + src/uu/base32/Cargo.toml | 4 +++ src/uu/base64/Cargo.toml | 4 +++ src/uu/basename/Cargo.toml | 4 +++ src/uu/basenc/Cargo.toml | 4 +++ src/uu/cksum/Cargo.toml | 4 +++ src/uu/comm/Cargo.toml | 4 +++ src/uu/cp/Cargo.toml | 4 +++ src/uu/csplit/Cargo.toml | 4 +++ src/uu/cut/Cargo.toml | 4 +++ src/uu/date/Cargo.toml | 4 +++ src/uu/dd/Cargo.toml | 4 +++ src/uu/dircolors/Cargo.toml | 4 +++ src/uu/expand/Cargo.toml | 4 +++ src/uu/expr/Cargo.toml | 4 +++ src/uu/factor/Cargo.toml | 4 +++ src/uu/fmt/Cargo.toml | 4 +++ src/uu/fold/Cargo.toml | 4 +++ src/uu/hashsum/Cargo.toml | 4 +++ src/uu/head/Cargo.toml | 4 +++ src/uu/join/Cargo.toml | 4 +++ src/uu/link/Cargo.toml | 4 +++ src/uu/ls/Cargo.toml | 4 +++ src/uu/more/Cargo.toml | 4 +++ src/uu/mv/Cargo.toml | 4 +++ src/uu/nl/Cargo.toml | 4 +++ src/uu/numfmt/Cargo.toml | 4 +++ src/uu/od/Cargo.toml | 4 +++ src/uu/paste/Cargo.toml | 4 +++ src/uu/pr/Cargo.toml | 4 +++ src/uu/printenv/Cargo.toml | 4 +++ src/uu/printf/Cargo.toml | 4 +++ src/uu/ptx/Cargo.toml | 4 +++ src/uu/readlink/Cargo.toml | 4 +++ src/uu/realpath/Cargo.toml | 4 +++ src/uu/relpath/Cargo.toml | 4 +++ src/uu/rm/Cargo.toml | 4 +++ src/uu/seq/Cargo.toml | 4 +++ src/uu/shred/Cargo.toml | 4 +++ src/uu/shuf/Cargo.toml | 4 +++ src/uu/split/Cargo.toml | 4 +++ src/uu/sum/Cargo.toml | 4 +++ src/uu/tac/Cargo.toml | 4 +++ src/uu/tail/Cargo.toml | 4 +++ src/uu/tee/Cargo.toml | 4 +++ src/uu/test/Cargo.toml | 4 +++ src/uu/tr/Cargo.toml | 4 +++ src/uu/truncate/Cargo.toml | 4 +++ src/uu/tsort/Cargo.toml | 4 +++ src/uu/unexpand/Cargo.toml | 4 +++ src/uu/uniq/Cargo.toml | 4 +++ src/uu/wc/Cargo.toml | 4 +++ 53 files changed, 237 insertions(+) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 68eaf3d06..d096ff43c 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -708,3 +708,35 @@ jobs: flags: ${{ steps.vars.outputs.CODECOV_FLAGS }} name: codecov-umbrella fail_ci_if_error: false + + unused_deps: + name: Unused deps + runs-on: ${{ matrix.job.os }} + strategy: + fail-fast: false + matrix: + job: + - { os: ubuntu-latest , features: feat_os_unix } + - { os: macos-latest , features: feat_os_macos } + - { os: windows-latest , features: feat_os_windows } + steps: + - uses: actions/checkout@v2 + - name: Install `rust` toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + default: true + profile: minimal + - name: Install `cargo-udeps` + uses: actions-rs/install@v0.1 + with: + crate: cargo-udeps + version: latest + use-tool-cache: true + env: + RUSTUP_TOOLCHAIN: stable + - name: Confirms there isn't any unused deps + shell: bash + run: | + cargo +nightly udeps --all-targets &> udeps.log || cat udeps.log + grep "seem to have been used" udeps.log diff --git a/.vscode/cspell.dictionaries/jargon.wordlist.txt b/.vscode/cspell.dictionaries/jargon.wordlist.txt index ed9e3d738..9b1d0a8da 100644 --- a/.vscode/cspell.dictionaries/jargon.wordlist.txt +++ b/.vscode/cspell.dictionaries/jargon.wordlist.txt @@ -117,6 +117,7 @@ toolchain truthy ucase unbuffered +udeps unescape unintuitive unprefixed diff --git a/src/uu/base32/Cargo.toml b/src/uu/base32/Cargo.toml index 3f6f79a0b..bc896bdb2 100644 --- a/src/uu/base32/Cargo.toml +++ b/src/uu/base32/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "base32" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/base64/Cargo.toml b/src/uu/base64/Cargo.toml index ff5a9aa48..011964dc1 100644 --- a/src/uu/base64/Cargo.toml +++ b/src/uu/base64/Cargo.toml @@ -23,3 +23,7 @@ uu_base32 = { version=">=0.0.6", package="uu_base32", path="../base32"} [[bin]] name = "base64" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/basename/Cargo.toml b/src/uu/basename/Cargo.toml index b5270eba9..b5b0a462c 100644 --- a/src/uu/basename/Cargo.toml +++ b/src/uu/basename/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "basename" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/basenc/Cargo.toml b/src/uu/basenc/Cargo.toml index 17cf0ec18..e8350d83d 100644 --- a/src/uu/basenc/Cargo.toml +++ b/src/uu/basenc/Cargo.toml @@ -23,3 +23,7 @@ uu_base32 = { version=">=0.0.6", package="uu_base32", path="../base32"} [[bin]] name = "basenc" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/cksum/Cargo.toml b/src/uu/cksum/Cargo.toml index b92b680c8..287a2285f 100644 --- a/src/uu/cksum/Cargo.toml +++ b/src/uu/cksum/Cargo.toml @@ -23,3 +23,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "cksum" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/comm/Cargo.toml b/src/uu/comm/Cargo.toml index 1deb094e2..e44c3511c 100644 --- a/src/uu/comm/Cargo.toml +++ b/src/uu/comm/Cargo.toml @@ -23,3 +23,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "comm" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/cp/Cargo.toml b/src/uu/cp/Cargo.toml index 66beb2501..62aef932b 100644 --- a/src/uu/cp/Cargo.toml +++ b/src/uu/cp/Cargo.toml @@ -45,3 +45,7 @@ path = "src/main.rs" [features] feat_selinux = ["selinux"] feat_acl = ["exacl"] + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/csplit/Cargo.toml b/src/uu/csplit/Cargo.toml index 3bc44b90c..40d4eebfa 100644 --- a/src/uu/csplit/Cargo.toml +++ b/src/uu/csplit/Cargo.toml @@ -24,3 +24,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "csplit" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/cut/Cargo.toml b/src/uu/cut/Cargo.toml index 6f92b39d1..c49450251 100644 --- a/src/uu/cut/Cargo.toml +++ b/src/uu/cut/Cargo.toml @@ -25,3 +25,7 @@ atty = "0.2" [[bin]] name = "cut" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/date/Cargo.toml b/src/uu/date/Cargo.toml index c144d0d81..d2af8c4f1 100644 --- a/src/uu/date/Cargo.toml +++ b/src/uu/date/Cargo.toml @@ -29,3 +29,7 @@ winapi = { version = "0.3", features = ["minwinbase", "sysinfoapi", "minwindef"] [[bin]] name = "date" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/dd/Cargo.toml b/src/uu/dd/Cargo.toml index a0ed1ab91..007ebb8ff 100644 --- a/src/uu/dd/Cargo.toml +++ b/src/uu/dd/Cargo.toml @@ -31,3 +31,7 @@ signal-hook = "0.3.9" [[bin]] name = "dd" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/dircolors/Cargo.toml b/src/uu/dircolors/Cargo.toml index e9e333ec6..ad95564f3 100644 --- a/src/uu/dircolors/Cargo.toml +++ b/src/uu/dircolors/Cargo.toml @@ -23,3 +23,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "dircolors" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/expand/Cargo.toml b/src/uu/expand/Cargo.toml index 5921ef679..e9b2cc747 100644 --- a/src/uu/expand/Cargo.toml +++ b/src/uu/expand/Cargo.toml @@ -23,3 +23,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "expand" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/expr/Cargo.toml b/src/uu/expr/Cargo.toml index 65d4fa636..035f00721 100644 --- a/src/uu/expr/Cargo.toml +++ b/src/uu/expr/Cargo.toml @@ -26,3 +26,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "expr" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/factor/Cargo.toml b/src/uu/factor/Cargo.toml index 76c06a34c..9d62e5f2b 100644 --- a/src/uu/factor/Cargo.toml +++ b/src/uu/factor/Cargo.toml @@ -34,3 +34,7 @@ path = "src/main.rs" [lib] path = "src/cli.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/fmt/Cargo.toml b/src/uu/fmt/Cargo.toml index dea0726a6..75b81c354 100644 --- a/src/uu/fmt/Cargo.toml +++ b/src/uu/fmt/Cargo.toml @@ -24,3 +24,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "fmt" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/fold/Cargo.toml b/src/uu/fold/Cargo.toml index 446be290d..7ec886264 100644 --- a/src/uu/fold/Cargo.toml +++ b/src/uu/fold/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "fold" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/hashsum/Cargo.toml b/src/uu/hashsum/Cargo.toml index b4da17b71..9ea142c8b 100644 --- a/src/uu/hashsum/Cargo.toml +++ b/src/uu/hashsum/Cargo.toml @@ -33,3 +33,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "hashsum" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/head/Cargo.toml b/src/uu/head/Cargo.toml index 1019ac74f..4fa4c0c81 100644 --- a/src/uu/head/Cargo.toml +++ b/src/uu/head/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "head" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/join/Cargo.toml b/src/uu/join/Cargo.toml index f108d5a4e..7e5ced498 100644 --- a/src/uu/join/Cargo.toml +++ b/src/uu/join/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "join" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/link/Cargo.toml b/src/uu/link/Cargo.toml index 025ac7554..d37ac6761 100644 --- a/src/uu/link/Cargo.toml +++ b/src/uu/link/Cargo.toml @@ -23,3 +23,7 @@ clap = { version = "2.33", features = ["wrap_help"] } [[bin]] name = "link" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/ls/Cargo.toml b/src/uu/ls/Cargo.toml index 6c4858a1c..e907e8e02 100644 --- a/src/uu/ls/Cargo.toml +++ b/src/uu/ls/Cargo.toml @@ -34,3 +34,7 @@ lazy_static = "1.4.0" [[bin]] name = "ls" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/more/Cargo.toml b/src/uu/more/Cargo.toml index d7bbe5c75..cd292eea9 100644 --- a/src/uu/more/Cargo.toml +++ b/src/uu/more/Cargo.toml @@ -33,3 +33,7 @@ nix = "0.19" [[bin]] name = "more" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/mv/Cargo.toml b/src/uu/mv/Cargo.toml index 9af0cb2a3..82b1da6e1 100644 --- a/src/uu/mv/Cargo.toml +++ b/src/uu/mv/Cargo.toml @@ -23,3 +23,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "mv" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/nl/Cargo.toml b/src/uu/nl/Cargo.toml index 57676768f..ca0d7827d 100644 --- a/src/uu/nl/Cargo.toml +++ b/src/uu/nl/Cargo.toml @@ -27,3 +27,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "nl" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/numfmt/Cargo.toml b/src/uu/numfmt/Cargo.toml index a3bdcf261..6239da7f9 100644 --- a/src/uu/numfmt/Cargo.toml +++ b/src/uu/numfmt/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "numfmt" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/od/Cargo.toml b/src/uu/od/Cargo.toml index 804183025..ee785e773 100644 --- a/src/uu/od/Cargo.toml +++ b/src/uu/od/Cargo.toml @@ -25,3 +25,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "od" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/paste/Cargo.toml b/src/uu/paste/Cargo.toml index 19a674c3e..c4873b1d0 100644 --- a/src/uu/paste/Cargo.toml +++ b/src/uu/paste/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "paste" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/pr/Cargo.toml b/src/uu/pr/Cargo.toml index fd46e817e..09993c3b9 100644 --- a/src/uu/pr/Cargo.toml +++ b/src/uu/pr/Cargo.toml @@ -27,3 +27,7 @@ regex = "1.0" [[bin]] name = "pr" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/printenv/Cargo.toml b/src/uu/printenv/Cargo.toml index 040997393..466f69af0 100644 --- a/src/uu/printenv/Cargo.toml +++ b/src/uu/printenv/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "printenv" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/printf/Cargo.toml b/src/uu/printf/Cargo.toml index a0bd27d8e..f4034083a 100644 --- a/src/uu/printf/Cargo.toml +++ b/src/uu/printf/Cargo.toml @@ -26,3 +26,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "printf" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/ptx/Cargo.toml b/src/uu/ptx/Cargo.toml index 852379e15..fea4e5c1f 100644 --- a/src/uu/ptx/Cargo.toml +++ b/src/uu/ptx/Cargo.toml @@ -27,3 +27,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "ptx" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/readlink/Cargo.toml b/src/uu/readlink/Cargo.toml index 9e0f939d1..8552f611d 100644 --- a/src/uu/readlink/Cargo.toml +++ b/src/uu/readlink/Cargo.toml @@ -23,3 +23,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "readlink" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/realpath/Cargo.toml b/src/uu/realpath/Cargo.toml index f5b9af2e7..3916c4ce6 100644 --- a/src/uu/realpath/Cargo.toml +++ b/src/uu/realpath/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "realpath" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/relpath/Cargo.toml b/src/uu/relpath/Cargo.toml index 89376c12d..bcb048af9 100644 --- a/src/uu/relpath/Cargo.toml +++ b/src/uu/relpath/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "relpath" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/rm/Cargo.toml b/src/uu/rm/Cargo.toml index c356f03e4..6099d137a 100644 --- a/src/uu/rm/Cargo.toml +++ b/src/uu/rm/Cargo.toml @@ -27,3 +27,7 @@ winapi = { version="0.3", features=[] } [[bin]] name = "rm" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/seq/Cargo.toml b/src/uu/seq/Cargo.toml index 68aa87bad..4618115cb 100644 --- a/src/uu/seq/Cargo.toml +++ b/src/uu/seq/Cargo.toml @@ -24,3 +24,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "seq" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/shred/Cargo.toml b/src/uu/shred/Cargo.toml index 5f7bebb4e..d87732d84 100644 --- a/src/uu/shred/Cargo.toml +++ b/src/uu/shred/Cargo.toml @@ -24,3 +24,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "shred" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/shuf/Cargo.toml b/src/uu/shuf/Cargo.toml index 5c99c6d26..bb3ccc710 100644 --- a/src/uu/shuf/Cargo.toml +++ b/src/uu/shuf/Cargo.toml @@ -23,3 +23,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "shuf" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/split/Cargo.toml b/src/uu/split/Cargo.toml index 6583d705e..d2168bf49 100644 --- a/src/uu/split/Cargo.toml +++ b/src/uu/split/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "split" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/sum/Cargo.toml b/src/uu/sum/Cargo.toml index 5a212d0d3..41f2d0a38 100644 --- a/src/uu/sum/Cargo.toml +++ b/src/uu/sum/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "sum" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/tac/Cargo.toml b/src/uu/tac/Cargo.toml index 4a91786aa..1e436e916 100644 --- a/src/uu/tac/Cargo.toml +++ b/src/uu/tac/Cargo.toml @@ -24,3 +24,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "tac" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/tail/Cargo.toml b/src/uu/tail/Cargo.toml index 0fe84670e..6fd05b1a9 100644 --- a/src/uu/tail/Cargo.toml +++ b/src/uu/tail/Cargo.toml @@ -33,3 +33,7 @@ libc = "0.2" [[bin]] name = "tail" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/tee/Cargo.toml b/src/uu/tee/Cargo.toml index 01c190698..900ef3564 100644 --- a/src/uu/tee/Cargo.toml +++ b/src/uu/tee/Cargo.toml @@ -24,3 +24,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "tee" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/test/Cargo.toml b/src/uu/test/Cargo.toml index b9931185c..3fe531d1d 100644 --- a/src/uu/test/Cargo.toml +++ b/src/uu/test/Cargo.toml @@ -26,3 +26,7 @@ redox_syscall = "0.2" [[bin]] name = "test" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/tr/Cargo.toml b/src/uu/tr/Cargo.toml index f75a540ee..450c562e0 100644 --- a/src/uu/tr/Cargo.toml +++ b/src/uu/tr/Cargo.toml @@ -24,3 +24,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "tr" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/truncate/Cargo.toml b/src/uu/truncate/Cargo.toml index 6441f2e14..e779e32ba 100644 --- a/src/uu/truncate/Cargo.toml +++ b/src/uu/truncate/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "truncate" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/tsort/Cargo.toml b/src/uu/tsort/Cargo.toml index ec9dd05f9..055615003 100644 --- a/src/uu/tsort/Cargo.toml +++ b/src/uu/tsort/Cargo.toml @@ -22,3 +22,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "tsort" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/unexpand/Cargo.toml b/src/uu/unexpand/Cargo.toml index a0aa3c1de..8b1169151 100644 --- a/src/uu/unexpand/Cargo.toml +++ b/src/uu/unexpand/Cargo.toml @@ -23,3 +23,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "unexpand" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/uniq/Cargo.toml b/src/uu/uniq/Cargo.toml index 856da9a63..06ba22688 100644 --- a/src/uu/uniq/Cargo.toml +++ b/src/uu/uniq/Cargo.toml @@ -24,3 +24,7 @@ uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_p [[bin]] name = "uniq" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] diff --git a/src/uu/wc/Cargo.toml b/src/uu/wc/Cargo.toml index 5884f3746..179b17c36 100644 --- a/src/uu/wc/Cargo.toml +++ b/src/uu/wc/Cargo.toml @@ -29,3 +29,7 @@ libc = "0.2" [[bin]] name = "wc" path = "src/main.rs" + +[package.metadata.cargo-udeps.ignore] +# Necessary for "make all" +normal = ["uucore_procs"] From 3f37ddbd22803a991ece4fa3fc78fda02e776697 Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Sat, 28 Aug 2021 13:47:31 +0200 Subject: [PATCH 21/21] hostname: Cleanup - Attach context to I/O errors - Make flags override each other - Support invalid unicode as argument - Call WsaCleanup() even on panic - Do not use deprecated std::mem::uninitialized() --- .../workspace.wordlist.txt | 2 + src/uu/hostname/src/hostname.rs | 136 +++++++++--------- 2 files changed, 73 insertions(+), 65 deletions(-) diff --git a/.vscode/cspell.dictionaries/workspace.wordlist.txt b/.vscode/cspell.dictionaries/workspace.wordlist.txt index 29957fb12..d37a59465 100644 --- a/.vscode/cspell.dictionaries/workspace.wordlist.txt +++ b/.vscode/cspell.dictionaries/workspace.wordlist.txt @@ -68,6 +68,7 @@ structs substr splitn trunc +uninit # * uutils basenc @@ -277,6 +278,7 @@ ULONG ULONGLONG UNLEN WCHAR +WSADATA errhandlingapi fileapi handleapi diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index 8852e0f43..2de6627e8 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -10,18 +10,13 @@ #[macro_use] extern crate uucore; -use clap::{crate_version, App, Arg, ArgMatches}; use std::collections::hash_set::HashSet; use std::net::ToSocketAddrs; use std::str; -#[cfg(windows)] -use uucore::error::UUsageError; -use uucore::error::{UResult, USimpleError}; -#[cfg(windows)] -use winapi::shared::minwindef::MAKEWORD; -#[cfg(windows)] -use winapi::um::winsock2::{WSACleanup, WSAStartup}; +use clap::{crate_version, App, Arg, ArgMatches}; + +use uucore::error::{FromIo, UResult}; static ABOUT: &str = "Display or set the system's host name."; @@ -31,45 +26,52 @@ static OPT_FQDN: &str = "fqdn"; static OPT_SHORT: &str = "short"; static OPT_HOST: &str = "host"; -#[uucore_procs::gen_uumain] -pub fn uumain(args: impl uucore::Args) -> UResult<()> { - #![allow(clippy::let_and_return)] - #[cfg(windows)] - unsafe { - #[allow(deprecated)] - let mut data = std::mem::uninitialized(); - if WSAStartup(MAKEWORD(2, 2), &mut data as *mut _) != 0 { - return Err(UUsageError::new( - 1, - "Failed to start Winsock 2.2".to_string(), - )); +#[cfg(windows)] +mod wsa { + use std::io; + + use winapi::shared::minwindef::MAKEWORD; + use winapi::um::winsock2::{WSACleanup, WSAStartup, WSADATA}; + + pub(super) struct WsaHandle(()); + + pub(super) fn start() -> io::Result { + let err = unsafe { + let mut data = std::mem::MaybeUninit::::uninit(); + WSAStartup(MAKEWORD(2, 2), data.as_mut_ptr()) + }; + if err != 0 { + Err(io::Error::from_raw_os_error(err)) + } else { + Ok(WsaHandle(())) } } - let result = execute(args); - #[cfg(windows)] - unsafe { - WSACleanup(); + + impl Drop for WsaHandle { + fn drop(&mut self) { + unsafe { + // This possibly returns an error but we can't handle it + let _err = WSACleanup(); + } + } } - result } fn usage() -> String { format!("{0} [OPTION]... [HOSTNAME]", uucore::execution_phrase()) } -fn execute(args: impl uucore::Args) -> UResult<()> { +#[uucore_procs::gen_uumain] +pub fn uumain(args: impl uucore::Args) -> UResult<()> { let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); - match matches.value_of(OPT_HOST) { + #[cfg(windows)] + let _handle = wsa::start().map_err_context(|| "failed to start Winsock".to_owned())?; + + match matches.value_of_os(OPT_HOST) { None => display_hostname(&matches), - Some(host) => { - if let Err(err) = hostname::set(host) { - return Err(USimpleError::new(1, format!("{}", err))); - } else { - Ok(()) - } - } + Some(host) => hostname::set(host).map_err_context(|| "failed to set hostname".to_owned()), } } @@ -81,64 +83,68 @@ pub fn uu_app() -> App<'static, 'static> { Arg::with_name(OPT_DOMAIN) .short("d") .long("domain") + .overrides_with_all(&[OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) .help("Display the name of the DNS domain if possible"), ) .arg( Arg::with_name(OPT_IP_ADDRESS) .short("i") .long("ip-address") + .overrides_with_all(&[OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) .help("Display the network address(es) of the host"), ) - // TODO: support --long .arg( Arg::with_name(OPT_FQDN) .short("f") .long("fqdn") + .overrides_with_all(&[OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) .help("Display the FQDN (Fully Qualified Domain Name) (default)"), ) - .arg(Arg::with_name(OPT_SHORT).short("s").long("short").help( - "Display the short hostname (the portion before the first dot) if \ - possible", - )) + .arg( + Arg::with_name(OPT_SHORT) + .short("s") + .long("short") + .overrides_with_all(&[OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) + .help("Display the short hostname (the portion before the first dot) if possible"), + ) .arg(Arg::with_name(OPT_HOST)) } fn display_hostname(matches: &ArgMatches) -> UResult<()> { - let hostname = hostname::get().unwrap().into_string().unwrap(); + let hostname = hostname::get() + .map_err_context(|| "failed to get hostname".to_owned())? + .to_string_lossy() + .into_owned(); if matches.is_present(OPT_IP_ADDRESS) { // XXX: to_socket_addrs needs hostname:port so append a dummy port and remove it later. // This was originally supposed to use std::net::lookup_host, but that seems to be // deprecated. Perhaps we should use the dns-lookup crate? let hostname = hostname + ":1"; - match hostname.to_socket_addrs() { - Ok(addresses) => { - let mut hashset = HashSet::new(); - let mut output = String::new(); - for addr in addresses { - // XXX: not sure why this is necessary... - if !hashset.contains(&addr) { - let mut ip = format!("{}", addr); - if ip.ends_with(":1") { - let len = ip.len(); - ip.truncate(len - 2); - } - output.push_str(&ip); - output.push(' '); - hashset.insert(addr); - } + let addresses = hostname + .to_socket_addrs() + .map_err_context(|| "failed to resolve socket addresses".to_owned())?; + let mut hashset = HashSet::new(); + let mut output = String::new(); + for addr in addresses { + // XXX: not sure why this is necessary... + if !hashset.contains(&addr) { + let mut ip = addr.to_string(); + if ip.ends_with(":1") { + let len = ip.len(); + ip.truncate(len - 2); } - let len = output.len(); - if len > 0 { - println!("{}", &output[0..len - 1]); - } - - Ok(()) - } - Err(f) => { - return Err(USimpleError::new(1, format!("{}", f))); + output.push_str(&ip); + output.push(' '); + hashset.insert(addr); } } + let len = output.len(); + if len > 0 { + println!("{}", &output[0..len - 1]); + } + + Ok(()) } else { if matches.is_present(OPT_SHORT) || matches.is_present(OPT_DOMAIN) { let mut it = hostname.char_indices().filter(|&ci| ci.1 == '.');