From 3acbd1c0482b03b96a63d14f13582b8cbfaf4ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Fuchs?= <86745544+Fuchczyk@users.noreply.github.com> Date: Wed, 17 Aug 2022 11:40:42 +0200 Subject: [PATCH 01/44] dd: Error message of invalid args is matched with GNU (#3831) --- src/uu/dd/src/dd.rs | 2 +- src/uu/dd/src/parseargs.rs | 14 +++++++-- tests/by-util/test_dd.rs | 59 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 94da4b7d3..4b3ad4434 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -146,7 +146,7 @@ impl Input { } opts.open(fname) - .map_err_context(|| "failed to open input file".to_string())? + .map_err_context(|| format!("failed to open {}", fname.quote()))? }; // The --skip and --iseek flags are additive. On a file, they seek. diff --git a/src/uu/dd/src/parseargs.rs b/src/uu/dd/src/parseargs.rs index 96ac55d75..701134ee1 100644 --- a/src/uu/dd/src/parseargs.rs +++ b/src/uu/dd/src/parseargs.rs @@ -35,6 +35,7 @@ pub enum ParseError { IbsOutOfRange, ObsOutOfRange, CbsOutOfRange, + InvalidNumber(String), } impl ParseError { @@ -56,6 +57,7 @@ impl ParseError { Self::IbsOutOfRange => Self::IbsOutOfRange, Self::ObsOutOfRange => Self::ObsOutOfRange, Self::CbsOutOfRange => Self::CbsOutOfRange, + Self::InvalidNumber(_) => Self::InvalidNumber(s), } } } @@ -79,7 +81,12 @@ impl std::fmt::Display for ParseError { write!(f, "Only one ov conv=excl or conv=nocreat may be specified") } Self::FlagNoMatch(arg) => { - write!(f, "Unrecognized iflag=FLAG or oflag=FLAG -> {}", arg) + // Additional message about 'dd --help' is displayed only in this situation. + write!( + f, + "invalid input flag: ‘{}’\nTry 'dd --help' for more information.", + arg + ) } Self::ConvFlagNoMatch(arg) => { write!(f, "Unrecognized conv=CONV -> {}", arg) @@ -115,6 +122,9 @@ impl std::fmt::Display for ParseError { Self::Unimplemented(arg) => { write!(f, "feature not implemented on this system -> {}", arg) } + Self::InvalidNumber(arg) => { + write!(f, "invalid number: ‘{}’", arg) + } } } } @@ -389,7 +399,7 @@ fn parse_bytes_no_x(s: &str) -> Result { (None, None, None) => match uucore::parse_size::parse_size(s) { Ok(n) => (n, 1), Err(ParseSizeError::InvalidSuffix(s)) | Err(ParseSizeError::ParseFailure(s)) => { - return Err(ParseError::MultiplierStringParseFailure(s)) + return Err(ParseError::InvalidNumber(s)) } Err(ParseSizeError::SizeTooBig(s)) => { return Err(ParseError::MultiplierStringOverflow(s)) diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index 8393248ef..a3a422ad8 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -1187,3 +1187,62 @@ fn test_final_stats_si_iec() { let s = result.stderr_str(); assert!(s.starts_with("2+0 records in\n2+0 records out\n1024 bytes (1 KB, 1024 B) copied,")); } + +#[test] +fn test_invalid_number_arg_gnu_compatibility() { + let commands = vec!["bs", "cbs", "count", "ibs", "obs", "seek", "skip"]; + + for command in commands { + new_ucmd!() + .args(&[format!("{}=", command)]) + .fails() + .stderr_is("dd: invalid number: ‘’"); + + new_ucmd!() + .args(&[format!("{}=29d", command)]) + .fails() + .stderr_is("dd: invalid number: ‘29d’"); + } +} + +#[test] +fn test_invalid_flag_arg_gnu_compatibility() { + let commands = vec!["iflag", "oflag"]; + + for command in commands { + new_ucmd!() + .args(&[format!("{}=", command)]) + .fails() + .stderr_is("dd: invalid input flag: ‘’\nTry 'dd --help' for more information."); + + new_ucmd!() + .args(&[format!("{}=29d", command)]) + .fails() + .stderr_is("dd: invalid input flag: ‘29d’\nTry 'dd --help' for more information."); + } +} + +#[test] +fn test_invalid_file_arg_gnu_compatibility() { + new_ucmd!() + .args(&["if="]) + .fails() + .stderr_is("dd: failed to open '': No such file or directory"); + + new_ucmd!() + .args(&["if=81as9bn8as9g302az8ns9.pdf.zip.pl.com"]) + .fails() + .stderr_is( + "dd: failed to open '81as9bn8as9g302az8ns9.pdf.zip.pl.com': No such file or directory", + ); + + new_ucmd!() + .args(&["of="]) + .fails() + .stderr_is("dd: failed to open '': No such file or directory"); + + new_ucmd!() + .args(&["of=81as9bn8as9g302az8ns9.pdf.zip.pl.com"]) + .pipe_in("") + .succeeds(); +} From f4df7ea4a005ccdd7a942596103b4bc35dc17ae7 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Tue, 16 Aug 2022 15:26:26 +0300 Subject: [PATCH 02/44] cargo +1.56.1 update --- Cargo.lock | 543 ++++++++++++++++++++++++---------------- src/bin/coreutils.rs | 4 +- src/uu/more/src/more.rs | 14 ++ 3 files changed, 338 insertions(+), 223 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 216619eb2..1ff2d07b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,6 +40,15 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" +[[package]] +name = "android_system_properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7ed72e1635e121ca3e79420540282af22da58be50de153d36f81ddc6b83aa9e" +dependencies = [ + "libc", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -114,7 +123,7 @@ dependencies = [ "log", "peeking_take_while", "proc-macro2", - "quote 1.0.18", + "quote 1.0.21", "regex", "rustc-hash", "shlex", @@ -172,6 +181,12 @@ dependencies = [ "regex-automata", ] +[[package]] +name = "bumpalo" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" + [[package]] name = "byte-unit" version = "4.0.14" @@ -222,22 +237,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.19" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" dependencies = [ - "libc", + "iana-time-zone", + "js-sys", "num-integer", "num-traits", "time 0.1.44", + "wasm-bindgen", "winapi 0.3.9", ] [[package]] name = "clang-sys" -version = "1.3.2" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf6b561dcf059c85bbe388e0a7b0a1469acb3934cc0cfa148613a830629e3049" +checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b" dependencies = [ "glob", "libc", @@ -261,9 +278,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.15" +version = "3.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bbe24bbd31a185bc2c4f7c2abe80bea13a20d57ee4e55be70ac512bdc76417" +checksum = "29e724a68d9319343bb3328c9cc2dfde263f4b3142ee1059a9980580171c954b" dependencies = [ "atty", "bitflags", @@ -278,11 +295,11 @@ dependencies = [ [[package]] name = "clap_complete" -version = "3.1.4" +version = "3.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da92e6facd8d73c22745a5d3cbb59bdf8e46e3235c923e516527d8e81eec14a4" +checksum = "e4179da71abd56c26b54dd0c248cc081c1f43b0a1a7e8448e28e57a29baa993d" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", ] [[package]] @@ -315,20 +332,26 @@ dependencies = [ "custom_derive", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + [[package]] name = "coreutils" version = "0.0.14" dependencies = [ "atty", "chrono", - "clap 3.2.15", + "clap 3.2.17", "clap_complete", "conv", "filetime", "glob", "hex-literal", "libc", - "nix", + "nix 0.24.2", "once_cell", "phf", "phf_codegen", @@ -518,7 +541,7 @@ dependencies = [ "cpp_common 0.5.7", "lazy_static", "proc-macro2", - "quote 1.0.18", + "quote 1.0.21", "syn", ] @@ -573,9 +596,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -583,9 +606,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" dependencies = [ "cfg-if 1.0.0", "crossbeam-epoch", @@ -594,33 +617,33 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.8" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" +checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" dependencies = [ "autocfg", "cfg-if 1.0.0", "crossbeam-utils", - "lazy_static", "memoffset", + "once_cell", "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.8" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" dependencies = [ "cfg-if 1.0.0", - "lazy_static", + "once_cell", ] [[package]] name = "crossterm" -version = "0.24.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9f7409c70a38a56216480fba371ee460207dd8926ccf5b4160591759559170" +checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" dependencies = [ "bitflags", "crossterm_winapi", @@ -643,9 +666,9 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.3" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", "typenum", @@ -653,21 +676,21 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" dependencies = [ - "quote 1.0.18", + "quote 1.0.21", "syn", ] [[package]] name = "ctrlc" -version = "3.2.2" +version = "3.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b37feaa84e6861e00a1f5e5aa8da3ee56d605c9992d33e082786754828e20865" +checksum = "1d91974fbbe88ec1df0c24a4f00f99583667a7e2e6272b2b92d294d81e462173" dependencies = [ - "nix", + "nix 0.25.0", "winapi 0.3.9", ] @@ -705,9 +728,9 @@ dependencies = [ [[package]] name = "diff" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "digest" @@ -746,9 +769,9 @@ checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541" [[package]] name = "either" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" [[package]] name = "env_logger" @@ -787,9 +810,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" dependencies = [ "instant", ] @@ -814,13 +837,11 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af" +checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" dependencies = [ - "cfg-if 1.0.0", "crc32fast", - "libc", "miniz_oxide", ] @@ -866,9 +887,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.5" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" dependencies = [ "typenum", "version_check", @@ -876,13 +897,13 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.10.0+wasi-snapshot-preview1", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -899,15 +920,9 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" - -[[package]] -name = "hashbrown" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ "ahash", ] @@ -957,13 +972,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] -name = "indexmap" -version = "1.8.1" +name = "iana-time-zone" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" +checksum = "ef5528d9c2817db4e10cc78f8d4c8228906e5854f389ff6b076cee3572a09d35" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "js-sys", + "wasm-bindgen", + "winapi 0.3.9", +] + +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", - "hashbrown 0.11.2", + "hashbrown", ] [[package]] @@ -1006,15 +1034,24 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" + +[[package]] +name = "js-sys" +version = "0.3.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +dependencies = [ + "wasm-bindgen", +] [[package]] name = "keccak" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" +checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838" [[package]] name = "kernel32-sys" @@ -1028,9 +1065,9 @@ dependencies = [ [[package]] name = "kqueue" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97caf428b83f7c86809b7450722cd1f2b1fc7fb23aa7b9dee7e72ed14d048352" +checksum = "4d6112e8f37b59803ac47a42d14f1f3a59bbf72fc6857ffc5be455e28a691f8e" dependencies = [ "kqueue-sys", "libc", @@ -1060,9 +1097,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.131" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "04c3b4822ccebfa39c02fc03d1534441b22ead323fa0f48bb7ddd8e6ba076a40" [[package]] name = "libloading" @@ -1095,9 +1132,9 @@ dependencies = [ [[package]] name = "lscolors" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a24e014efe73b727e5792b6f422a23c04b10ba9d8cdc74b197a25a08db7eac86" +checksum = "2b3501e949531fefe2d23b2d5fb9bbb0f450e528bbfcdcd78ad04f28c3dea550" dependencies = [ "ansi_term", ] @@ -1134,9 +1171,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memmap2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2e4455be2010e8c5e77f0d10234b30f3a636a5305725609b5a71ad00d22577" +checksum = "95af15f345b17af2efc8ead6080fb8bc376f8cec1b35277b935637595fe77498" dependencies = [ "libc", ] @@ -1158,18 +1195,18 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.5.1" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082" +checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" dependencies = [ "adler", ] [[package]] name = "mio" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" +checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" dependencies = [ "libc", "log", @@ -1189,6 +1226,18 @@ dependencies = [ "memoffset", ] +[[package]] +name = "nix" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb" +dependencies = [ + "autocfg", + "bitflags", + "cfg-if 1.0.0", + "libc", +] + [[package]] name = "nom" version = "7.1.1" @@ -1298,9 +1347,9 @@ dependencies = [ [[package]] name = "onig_sys" -version = "69.8.0" +version = "69.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf3fbc9b931b6c9af85d219c7943c274a6ad26cff7488a2210215edd5f49bf8" +checksum = "7b829e3d7e9cc74c7e315ee8edb185bf4190da5acde74afd7fc59c35b1f086e7" dependencies = [ "cc", "pkg-config", @@ -1313,7 +1362,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" dependencies = [ "dlv-list", - "hashbrown 0.12.0", + "hashbrown", ] [[package]] @@ -1350,7 +1399,7 @@ dependencies = [ "Inflector", "proc-macro-error", "proc-macro2", - "quote 1.0.18", + "quote 1.0.21", "syn", ] @@ -1365,9 +1414,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", "parking_lot_core", @@ -1388,9 +1437,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" +checksum = "9423e2b32f7a043629287a536f21951e8c6a82482d0acb1eeebfc90bc2225b22" [[package]] name = "peeking_take_while" @@ -1478,7 +1527,7 @@ checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", "proc-macro2", - "quote 1.0.18", + "quote 1.0.21", "syn", "version_check", ] @@ -1490,15 +1539,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", - "quote 1.0.18", + "quote 1.0.21", "version_check", ] [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" dependencies = [ "unicode-ident", ] @@ -1528,9 +1577,9 @@ checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" [[package]] name = "quote" -version = "1.0.18" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -1591,9 +1640,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534cfe58d6a18cc17120fbf4635d53d14691c1fe4d951064df9bd326178d7d5a" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] @@ -1691,9 +1740,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustversion" -version = "1.0.6" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" +checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" [[package]] name = "same-file" @@ -1852,13 +1901,13 @@ checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" [[package]] name = "strum_macros" -version = "0.24.2" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4faebde00e8ff94316c01800f9054fd2ba77d30d9e922541913051d1d978918b" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" dependencies = [ "heck", "proc-macro2", - "quote 1.0.18", + "quote 1.0.21", "rustversion", "syn", ] @@ -1871,12 +1920,12 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.95" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" +checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" dependencies = [ "proc-macro2", - "quote 1.0.18", + "quote 1.0.21", "unicode-ident", ] @@ -1984,7 +2033,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" dependencies = [ "proc-macro2", - "quote 1.0.18", + "quote 1.0.21", "syn", ] @@ -2025,9 +2074,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "unicode-ident" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" +checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "unicode-linebreak" @@ -2098,7 +2147,7 @@ checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" name = "uu_arch" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "platform-info", "uucore", ] @@ -2107,7 +2156,7 @@ dependencies = [ name = "uu_base32" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2123,7 +2172,7 @@ dependencies = [ name = "uu_basename" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2131,7 +2180,7 @@ dependencies = [ name = "uu_basenc" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uu_base32", "uucore", ] @@ -2141,8 +2190,8 @@ name = "uu_cat" version = "0.0.14" dependencies = [ "atty", - "clap 3.2.15", - "nix", + "clap 3.2.17", + "nix 0.24.2", "thiserror", "unix_socket", "uucore", @@ -2152,7 +2201,7 @@ dependencies = [ name = "uu_chcon" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "fts-sys", "libc", "selinux", @@ -2164,7 +2213,7 @@ dependencies = [ name = "uu_chgrp" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2172,7 +2221,7 @@ dependencies = [ name = "uu_chmod" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", ] @@ -2181,7 +2230,7 @@ dependencies = [ name = "uu_chown" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2189,7 +2238,7 @@ dependencies = [ name = "uu_chroot" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2197,7 +2246,7 @@ dependencies = [ name = "uu_cksum" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2205,7 +2254,7 @@ dependencies = [ name = "uu_comm" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2213,7 +2262,7 @@ dependencies = [ name = "uu_cp" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "exacl", "filetime", "libc", @@ -2229,7 +2278,7 @@ dependencies = [ name = "uu_csplit" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "regex", "thiserror", "uucore", @@ -2241,7 +2290,7 @@ version = "0.0.14" dependencies = [ "atty", "bstr", - "clap 3.2.15", + "clap 3.2.17", "memchr 2.5.0", "uucore", ] @@ -2251,7 +2300,7 @@ name = "uu_date" version = "0.0.14" dependencies = [ "chrono", - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", "winapi 0.3.9", @@ -2262,7 +2311,7 @@ name = "uu_dd" version = "0.0.14" dependencies = [ "byte-unit", - "clap 3.2.15", + "clap 3.2.17", "gcd", "libc", "signal-hook", @@ -2273,7 +2322,7 @@ dependencies = [ name = "uu_df" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "unicode-width", "uucore", ] @@ -2282,7 +2331,7 @@ dependencies = [ name = "uu_dir" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "selinux", "uu_ls", "uucore", @@ -2292,7 +2341,7 @@ dependencies = [ name = "uu_dircolors" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "glob", "uucore", ] @@ -2301,7 +2350,7 @@ dependencies = [ name = "uu_dirname" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2310,7 +2359,7 @@ name = "uu_du" version = "0.0.14" dependencies = [ "chrono", - "clap 3.2.15", + "clap 3.2.17", "glob", "uucore", "winapi 0.3.9", @@ -2320,7 +2369,7 @@ dependencies = [ name = "uu_echo" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2328,7 +2377,7 @@ dependencies = [ name = "uu_env" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "rust-ini", "uucore", ] @@ -2337,7 +2386,7 @@ dependencies = [ name = "uu_expand" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "unicode-width", "uucore", ] @@ -2346,7 +2395,7 @@ dependencies = [ name = "uu_expr" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "num-bigint", "num-traits", "onig", @@ -2357,7 +2406,7 @@ dependencies = [ name = "uu_factor" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "coz", "num-traits", "paste", @@ -2371,7 +2420,7 @@ dependencies = [ name = "uu_false" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2379,7 +2428,7 @@ dependencies = [ name = "uu_fmt" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "unicode-width", "uucore", ] @@ -2388,7 +2437,7 @@ dependencies = [ name = "uu_fold" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2396,7 +2445,7 @@ dependencies = [ name = "uu_groups" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2406,7 +2455,7 @@ version = "0.0.14" dependencies = [ "blake2b_simd", "blake3", - "clap 3.2.15", + "clap 3.2.17", "digest", "hex", "md-5", @@ -2422,7 +2471,7 @@ dependencies = [ name = "uu_head" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "memchr 2.5.0", "uucore", ] @@ -2431,7 +2480,7 @@ dependencies = [ name = "uu_hostid" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", ] @@ -2440,7 +2489,7 @@ dependencies = [ name = "uu_hostname" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "hostname", "uucore", "winapi 0.3.9", @@ -2450,7 +2499,7 @@ dependencies = [ name = "uu_id" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "selinux", "uucore", ] @@ -2459,7 +2508,7 @@ dependencies = [ name = "uu_install" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "file_diff", "filetime", "libc", @@ -2471,7 +2520,7 @@ dependencies = [ name = "uu_join" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "memchr 2.5.0", "uucore", ] @@ -2480,8 +2529,8 @@ dependencies = [ name = "uu_kill" version = "0.0.14" dependencies = [ - "clap 3.2.15", - "nix", + "clap 3.2.17", + "nix 0.24.2", "uucore", ] @@ -2489,7 +2538,7 @@ dependencies = [ name = "uu_link" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2497,7 +2546,7 @@ dependencies = [ name = "uu_ln" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2505,7 +2554,7 @@ dependencies = [ name = "uu_logname" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", ] @@ -2516,7 +2565,7 @@ version = "0.0.14" dependencies = [ "atty", "chrono", - "clap 3.2.15", + "clap 3.2.17", "glob", "lscolors", "number_prefix", @@ -2532,7 +2581,7 @@ dependencies = [ name = "uu_mkdir" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2540,7 +2589,7 @@ dependencies = [ name = "uu_mkfifo" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", ] @@ -2549,7 +2598,7 @@ dependencies = [ name = "uu_mknod" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", ] @@ -2558,7 +2607,7 @@ dependencies = [ name = "uu_mktemp" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "rand", "tempfile", "uucore", @@ -2569,9 +2618,9 @@ name = "uu_more" version = "0.0.14" dependencies = [ "atty", - "clap 3.2.15", + "clap 3.2.17", "crossterm", - "nix", + "nix 0.24.2", "unicode-segmentation", "unicode-width", "uucore", @@ -2581,7 +2630,7 @@ dependencies = [ name = "uu_mv" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "fs_extra", "uucore", ] @@ -2590,9 +2639,9 @@ dependencies = [ name = "uu_nice" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", - "nix", + "nix 0.24.2", "uucore", ] @@ -2600,7 +2649,7 @@ dependencies = [ name = "uu_nl" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "regex", "uucore", ] @@ -2610,7 +2659,7 @@ name = "uu_nohup" version = "0.0.14" dependencies = [ "atty", - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", ] @@ -2619,7 +2668,7 @@ dependencies = [ name = "uu_nproc" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "num_cpus", "uucore", @@ -2629,7 +2678,7 @@ dependencies = [ name = "uu_numfmt" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2638,7 +2687,7 @@ name = "uu_od" version = "0.0.14" dependencies = [ "byteorder", - "clap 3.2.15", + "clap 3.2.17", "half", "uucore", ] @@ -2647,7 +2696,7 @@ dependencies = [ name = "uu_paste" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2655,7 +2704,7 @@ dependencies = [ name = "uu_pathchk" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", ] @@ -2664,7 +2713,7 @@ dependencies = [ name = "uu_pinky" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2673,7 +2722,7 @@ name = "uu_pr" version = "0.0.14" dependencies = [ "chrono", - "clap 3.2.15", + "clap 3.2.17", "itertools", "quick-error", "regex", @@ -2684,7 +2733,7 @@ dependencies = [ name = "uu_printenv" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2692,7 +2741,7 @@ dependencies = [ name = "uu_printf" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2700,7 +2749,7 @@ dependencies = [ name = "uu_ptx" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "regex", "uucore", ] @@ -2709,7 +2758,7 @@ dependencies = [ name = "uu_pwd" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2717,7 +2766,7 @@ dependencies = [ name = "uu_readlink" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2725,7 +2774,7 @@ dependencies = [ name = "uu_realpath" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2733,7 +2782,7 @@ dependencies = [ name = "uu_relpath" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2741,7 +2790,7 @@ dependencies = [ name = "uu_rm" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "remove_dir_all 0.7.0", "uucore", "walkdir", @@ -2752,7 +2801,7 @@ dependencies = [ name = "uu_rmdir" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", ] @@ -2761,7 +2810,7 @@ dependencies = [ name = "uu_runcon" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "selinux", "thiserror", @@ -2773,7 +2822,7 @@ name = "uu_seq" version = "0.0.14" dependencies = [ "bigdecimal", - "clap 3.2.15", + "clap 3.2.17", "num-bigint", "num-traits", "uucore", @@ -2783,7 +2832,7 @@ dependencies = [ name = "uu_shred" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "rand", "uucore", ] @@ -2792,7 +2841,7 @@ dependencies = [ name = "uu_shuf" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "memchr 2.5.0", "rand", "rand_core", @@ -2803,7 +2852,7 @@ dependencies = [ name = "uu_sleep" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2812,7 +2861,7 @@ name = "uu_sort" version = "0.0.14" dependencies = [ "binary-heap-plus", - "clap 3.2.15", + "clap 3.2.17", "compare", "ctrlc", "fnv", @@ -2830,7 +2879,7 @@ dependencies = [ name = "uu_split" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "memchr 2.5.0", "uucore", ] @@ -2839,7 +2888,7 @@ dependencies = [ name = "uu_stat" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2847,7 +2896,7 @@ dependencies = [ name = "uu_stdbuf" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "tempfile", "uu_stdbuf_libstdbuf", "uucore", @@ -2867,7 +2916,7 @@ dependencies = [ name = "uu_sum" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2875,7 +2924,7 @@ dependencies = [ name = "uu_sync" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", "winapi 0.3.9", @@ -2885,7 +2934,7 @@ dependencies = [ name = "uu_tac" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "memchr 2.5.0", "memmap2", "regex", @@ -2896,9 +2945,9 @@ dependencies = [ name = "uu_tail" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", - "nix", + "nix 0.24.2", "notify", "uucore", "winapi 0.3.9", @@ -2909,7 +2958,7 @@ dependencies = [ name = "uu_tee" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "retain_mut", "uucore", @@ -2919,7 +2968,7 @@ dependencies = [ name = "uu_test" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "redox_syscall", "uucore", @@ -2929,9 +2978,9 @@ dependencies = [ name = "uu_timeout" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", - "nix", + "nix 0.24.2", "uucore", ] @@ -2939,7 +2988,7 @@ dependencies = [ name = "uu_touch" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "filetime", "time 0.3.9", "uucore", @@ -2950,7 +2999,7 @@ dependencies = [ name = "uu_tr" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "nom", "uucore", ] @@ -2959,7 +3008,7 @@ dependencies = [ name = "uu_true" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2967,7 +3016,7 @@ dependencies = [ name = "uu_truncate" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2975,7 +3024,7 @@ dependencies = [ name = "uu_tsort" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -2984,7 +3033,7 @@ name = "uu_tty" version = "0.0.14" dependencies = [ "atty", - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", ] @@ -2993,7 +3042,7 @@ dependencies = [ name = "uu_uname" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "platform-info", "uucore", ] @@ -3002,7 +3051,7 @@ dependencies = [ name = "uu_unexpand" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "unicode-width", "uucore", ] @@ -3011,7 +3060,7 @@ dependencies = [ name = "uu_uniq" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "strum", "strum_macros", "uucore", @@ -3021,7 +3070,7 @@ dependencies = [ name = "uu_unlink" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -3030,7 +3079,7 @@ name = "uu_uptime" version = "0.0.14" dependencies = [ "chrono", - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -3038,7 +3087,7 @@ dependencies = [ name = "uu_users" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -3046,7 +3095,7 @@ dependencies = [ name = "uu_vdir" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "selinux", "uu_ls", "uucore", @@ -3057,9 +3106,9 @@ name = "uu_wc" version = "0.0.14" dependencies = [ "bytecount", - "clap 3.2.15", + "clap 3.2.17", "libc", - "nix", + "nix 0.24.2", "unicode-width", "utf-8", "uucore", @@ -3069,7 +3118,7 @@ dependencies = [ name = "uu_who" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "uucore", ] @@ -3077,7 +3126,7 @@ dependencies = [ name = "uu_whoami" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", "uucore", "winapi 0.3.9", @@ -3087,9 +3136,9 @@ dependencies = [ name = "uu_yes" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "libc", - "nix", + "nix 0.24.2", "uucore", ] @@ -3097,7 +3146,7 @@ dependencies = [ name = "uucore" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "data-encoding", "data-encoding-macro", "dns-lookup", @@ -3105,7 +3154,7 @@ dependencies = [ "glob", "itertools", "libc", - "nix", + "nix 0.24.2", "once_cell", "os_display", "thiserror", @@ -3123,14 +3172,14 @@ name = "uucore_procs" version = "0.0.14" dependencies = [ "proc-macro2", - "quote 1.0.18", + "quote 1.0.21", ] [[package]] name = "uuid" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6d5d669b51467dcf7b2f1a796ce0f955f05f01cafda6c19d6e95f730df29238" +checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f" [[package]] name = "vec_map" @@ -3167,6 +3216,60 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote 1.0.21", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +dependencies = [ + "quote 1.0.21", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +dependencies = [ + "proc-macro2", + "quote 1.0.21", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" + [[package]] name = "which" version = "4.2.5" @@ -3180,9 +3283,9 @@ dependencies = [ [[package]] name = "wild" -version = "2.0.4" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "035793abb854745033f01a07647a79831eba29ec0be377205f2a25b0aa830020" +checksum = "05b116685a6be0c52f5a103334cbff26db643826c7b3735fc0a3ba9871310a74" dependencies = [ "glob", ] diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 52daf126c..a6fb11055 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -147,9 +147,7 @@ fn gen_completions( ) .arg( Arg::new("shell") - .value_parser(clap::builder::PossibleValuesParser::new( - Shell::possible_values(), - )) + .value_parser(clap::builder::EnumValueParser::::new()) .required(true), ) .get_matches_from(std::iter::once(OsString::from("completion")).chain(args)); diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index d4be472c8..e701b15fc 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -18,6 +18,7 @@ use std::{ extern crate nix; use clap::{crate_version, Arg, Command}; +use crossterm::event::KeyEventKind; use crossterm::{ event::{self, Event, KeyCode, KeyEvent, KeyModifiers}, execute, queue, @@ -229,13 +230,21 @@ fn more(buff: &str, stdout: &mut Stdout, next_file: Option<&str>, silent: bool) let mut wrong_key = None; if event::poll(Duration::from_millis(10)).unwrap() { match event::read().unwrap() { + Event::Key(KeyEvent { + kind: KeyEventKind::Release, + .. + }) => continue, Event::Key(KeyEvent { code: KeyCode::Char('q'), modifiers: KeyModifiers::NONE, + kind: KeyEventKind::Press, + .. }) | Event::Key(KeyEvent { code: KeyCode::Char('c'), modifiers: KeyModifiers::CONTROL, + kind: KeyEventKind::Press, + .. }) => { reset_term(stdout); std::process::exit(0); @@ -243,10 +252,12 @@ fn more(buff: &str, stdout: &mut Stdout, next_file: Option<&str>, silent: bool) Event::Key(KeyEvent { code: KeyCode::Down, modifiers: KeyModifiers::NONE, + .. }) | Event::Key(KeyEvent { code: KeyCode::Char(' '), modifiers: KeyModifiers::NONE, + .. }) => { if pager.should_close() { return Ok(()); @@ -257,12 +268,14 @@ fn more(buff: &str, stdout: &mut Stdout, next_file: Option<&str>, silent: bool) Event::Key(KeyEvent { code: KeyCode::Up, modifiers: KeyModifiers::NONE, + .. }) => { pager.page_up(); } Event::Key(KeyEvent { code: KeyCode::Char('j'), modifiers: KeyModifiers::NONE, + .. }) => { if pager.should_close() { return Ok(()); @@ -273,6 +286,7 @@ fn more(buff: &str, stdout: &mut Stdout, next_file: Option<&str>, silent: bool) Event::Key(KeyEvent { code: KeyCode::Char('k'), modifiers: KeyModifiers::NONE, + .. }) => { pager.prev_line(); } From 9cd898b885dc0bf61d5e50861eb982c9a8c73fd5 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Tue, 16 Aug 2022 15:37:58 +0300 Subject: [PATCH 03/44] remove nix 0.24.2 dependency --- Cargo.lock | 42 ++++++++++++++++++--------------------- Cargo.toml | 2 +- src/uu/cat/Cargo.toml | 2 +- src/uu/kill/Cargo.toml | 2 +- src/uu/more/Cargo.toml | 2 +- src/uu/nice/Cargo.toml | 2 +- src/uu/tail/Cargo.toml | 2 +- src/uu/timeout/Cargo.toml | 2 +- src/uu/wc/Cargo.toml | 2 +- src/uu/yes/Cargo.toml | 2 +- src/uucore/Cargo.toml | 2 +- 11 files changed, 29 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ff2d07b4..ba035a72c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,7 +351,7 @@ dependencies = [ "glob", "hex-literal", "libc", - "nix 0.24.2", + "nix", "once_cell", "phf", "phf_codegen", @@ -690,7 +690,7 @@ version = "3.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d91974fbbe88ec1df0c24a4f00f99583667a7e2e6272b2b92d294d81e462173" dependencies = [ - "nix 0.25.0", + "nix", "winapi 0.3.9", ] @@ -1214,18 +1214,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "nix" -version = "0.24.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" -dependencies = [ - "bitflags", - "cfg-if 1.0.0", - "libc", - "memoffset", -] - [[package]] name = "nix" version = "0.25.0" @@ -1236,6 +1224,8 @@ dependencies = [ "bitflags", "cfg-if 1.0.0", "libc", + "memoffset", + "pin-utils", ] [[package]] @@ -1485,6 +1475,12 @@ dependencies = [ "siphasher", ] +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.25" @@ -2191,7 +2187,7 @@ version = "0.0.14" dependencies = [ "atty", "clap 3.2.17", - "nix 0.24.2", + "nix", "thiserror", "unix_socket", "uucore", @@ -2530,7 +2526,7 @@ name = "uu_kill" version = "0.0.14" dependencies = [ "clap 3.2.17", - "nix 0.24.2", + "nix", "uucore", ] @@ -2620,7 +2616,7 @@ dependencies = [ "atty", "clap 3.2.17", "crossterm", - "nix 0.24.2", + "nix", "unicode-segmentation", "unicode-width", "uucore", @@ -2641,7 +2637,7 @@ version = "0.0.14" dependencies = [ "clap 3.2.17", "libc", - "nix 0.24.2", + "nix", "uucore", ] @@ -2947,7 +2943,7 @@ version = "0.0.14" dependencies = [ "clap 3.2.17", "libc", - "nix 0.24.2", + "nix", "notify", "uucore", "winapi 0.3.9", @@ -2980,7 +2976,7 @@ version = "0.0.14" dependencies = [ "clap 3.2.17", "libc", - "nix 0.24.2", + "nix", "uucore", ] @@ -3108,7 +3104,7 @@ dependencies = [ "bytecount", "clap 3.2.17", "libc", - "nix 0.24.2", + "nix", "unicode-width", "utf-8", "uucore", @@ -3138,7 +3134,7 @@ version = "0.0.14" dependencies = [ "clap 3.2.17", "libc", - "nix 0.24.2", + "nix", "uucore", ] @@ -3154,7 +3150,7 @@ dependencies = [ "glob", "itertools", "libc", - "nix 0.24.2", + "nix", "once_cell", "os_display", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 9c540531c..134f73925 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -402,7 +402,7 @@ hex-literal = "0.3.1" rlimit = "0.8.3" [target.'cfg(unix)'.dev-dependencies] -nix = { version = "0.24.2", default-features = false, features = ["process", "signal", "user"] } +nix = { version = "0.25", default-features = false, features = ["process", "signal", "user"] } rust-users = { version="0.11", package="users" } unix_socket = "0.5.0" diff --git a/src/uu/cat/Cargo.toml b/src/uu/cat/Cargo.toml index 4d4793b94..36265d380 100644 --- a/src/uu/cat/Cargo.toml +++ b/src/uu/cat/Cargo.toml @@ -22,7 +22,7 @@ uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=[ [target.'cfg(unix)'.dependencies] unix_socket = "0.5.0" -nix = { version = "0.24.2", default-features = false } +nix = { version = "0.25", default-features = false } [[bin]] name = "cat" diff --git a/src/uu/kill/Cargo.toml b/src/uu/kill/Cargo.toml index 3632f2cf7..8a5713a49 100644 --- a/src/uu/kill/Cargo.toml +++ b/src/uu/kill/Cargo.toml @@ -16,7 +16,7 @@ path = "src/kill.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -nix = { version = "0.24.2", features = ["signal"] } +nix = { version = "0.25", features = ["signal"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["signals"] } [[bin]] diff --git a/src/uu/more/Cargo.toml b/src/uu/more/Cargo.toml index 37afd24f1..160ae7acf 100644 --- a/src/uu/more/Cargo.toml +++ b/src/uu/more/Cargo.toml @@ -23,7 +23,7 @@ unicode-width = "0.1.7" unicode-segmentation = "1.9.0" [target.'cfg(all(unix, not(target_os = "fuchsia")))'.dependencies] -nix = { version = "0.24.2", default-features = false } +nix = { version = "0.25", default-features = false } [[bin]] name = "more" diff --git a/src/uu/nice/Cargo.toml b/src/uu/nice/Cargo.toml index b838ec2a2..650a5cbf8 100644 --- a/src/uu/nice/Cargo.toml +++ b/src/uu/nice/Cargo.toml @@ -17,7 +17,7 @@ path = "src/nice.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } libc = "0.2.126" -nix = { version = "0.24.2", default-features = false } +nix = { version = "0.25", default-features = false } uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } [[bin]] diff --git a/src/uu/tail/Cargo.toml b/src/uu/tail/Cargo.toml index 269bb490d..8c51de5fd 100644 --- a/src/uu/tail/Cargo.toml +++ b/src/uu/tail/Cargo.toml @@ -26,7 +26,7 @@ winapi = { version="0.3", features=["fileapi", "handleapi", "processthreadsapi", winapi-util = { version="0.1.5" } [target.'cfg(unix)'.dependencies] -nix = { version = "0.24.2", features = ["fs"] } +nix = { version = "0.25", features = ["fs"] } [[bin]] name = "tail" diff --git a/src/uu/timeout/Cargo.toml b/src/uu/timeout/Cargo.toml index c74ec413c..b87f96a39 100644 --- a/src/uu/timeout/Cargo.toml +++ b/src/uu/timeout/Cargo.toml @@ -17,7 +17,7 @@ path = "src/timeout.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } libc = "0.2.126" -nix = { version = "0.24.2", default-features = false, features = ["signal"] } +nix = { version = "0.25", default-features = false, features = ["signal"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["process", "signals"] } [[bin]] diff --git a/src/uu/wc/Cargo.toml b/src/uu/wc/Cargo.toml index c926d2431..9b8fe993c 100644 --- a/src/uu/wc/Cargo.toml +++ b/src/uu/wc/Cargo.toml @@ -22,7 +22,7 @@ utf-8 = "0.7.6" unicode-width = "0.1.8" [target.'cfg(unix)'.dependencies] -nix = { version = "0.24.2", default-features = false } +nix = { version = "0.25", default-features = false } libc = "0.2" [[bin]] diff --git a/src/uu/yes/Cargo.toml b/src/uu/yes/Cargo.toml index 73e19d9ab..fcac80f2c 100644 --- a/src/uu/yes/Cargo.toml +++ b/src/uu/yes/Cargo.toml @@ -20,7 +20,7 @@ libc = "0.2.126" uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["pipes"] } [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] -nix = { version = "0.24.2", default-features = false } +nix = { version = "0.25", default-features = false } [[bin]] name = "yes" diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index 45c750739..d6f944751 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -38,7 +38,7 @@ os_display = "0.1.3" [target.'cfg(unix)'.dependencies] walkdir = { version="2.3.2", optional=true } -nix = { version = "0.24.2", optional = true, default-features = false, features = ["fs", "uio", "zerocopy"] } +nix = { version = "0.25", optional = true, default-features = false, features = ["fs", "uio", "zerocopy"] } [dev-dependencies] clap = "3.2" From 33ba5cbc93a96e566ac30b8afa4212d5616b9e76 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Tue, 16 Aug 2022 15:50:19 +0300 Subject: [PATCH 04/44] downgrade unicode-ident to 1.0.0 --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba035a72c..fd0d4a297 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2070,9 +2070,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" [[package]] name = "unicode-linebreak" From 52d767ed5a9e29f7b24bdc7acca8c1cc0fd179be Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Tue, 16 Aug 2022 15:51:32 +0300 Subject: [PATCH 05/44] test_pr: follow clippy advice --- tests/by-util/test_pr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs index fdbd19941..a7d2dccb5 100644 --- a/tests/by-util/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -28,7 +28,7 @@ fn all_minutes(from: DateTime, to: DateTime) -> Vec { let mut current = from; while current < to { vec.push(current.format(FORMAT).to_string()); - current = current + Duration::minutes(1); + current += Duration::minutes(1); } vec } From dc12639995e406c1e4d4c864fccf8515ad33e3ea Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Tue, 16 Aug 2022 17:22:33 +0300 Subject: [PATCH 06/44] Fix completion with a clap update --- src/bin/coreutils.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index a6fb11055..c6914db3f 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -153,14 +153,13 @@ fn gen_completions( .get_matches_from(std::iter::once(OsString::from("completion")).chain(args)); let utility = matches.value_of("utility").unwrap(); - let shell = matches.value_of("shell").unwrap(); + let shell = matches.get_one::("shell").unwrap().to_owned(); let mut command = if utility == "coreutils" { gen_coreutils_app(util_map) } else { util_map.get(utility).unwrap().1() }; - let shell: Shell = shell.parse().unwrap(); let bin_name = std::env::var("PROG_PREFIX").unwrap_or_default() + utility; clap_complete::generate(shell, &mut command, bin_name, &mut io::stdout()); From ec23d02b19091567e76f24e8984a547a8ee514ee Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Tue, 16 Aug 2022 19:40:41 +0300 Subject: [PATCH 07/44] update unicode-ident to 1.0.3, allow Unicode-DFS-2016 License --- Cargo.lock | 4 ++-- deny.toml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd0d4a297..ba035a72c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2070,9 +2070,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "unicode-ident" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" +checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "unicode-linebreak" diff --git a/deny.toml b/deny.toml index ecc738cfe..fb076dd5e 100644 --- a/deny.toml +++ b/deny.toml @@ -30,6 +30,7 @@ allow = [ "BSD-3-Clause", "CC0-1.0", "MPL-2.0", # XXX considered copyleft? + "Unicode-DFS-2016", ] copyleft = "deny" allow-osi-fsf-free = "neither" From cdc664305e7d7d147018773ebbdd14d8a6bdd197 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Thu, 11 Aug 2022 22:38:58 +0300 Subject: [PATCH 08/44] tail: reuse opened file with the same descriptor when --follow=descriptor and renamed --- src/uu/tail/src/tail.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 486a7c127..32ebb21b0 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -1037,21 +1037,28 @@ fn handle_event( if settings.follow_descriptor() { let new_path = event.paths.last().unwrap(); paths.push(new_path.to_owned()); - // Open new file and seek to End: - let mut file = File::open(&new_path)?; - file.seek(SeekFrom::End(0))?; + // Remove old reader + let old_reader = files.remove(event_path).reader; + let reader = if old_reader.is_some() { + // Use old reader with the same file descriptor if there is one + old_reader + } else if let Ok(file) = File::open(&new_path) { + // Open new file tail from start + Some(Box::new(BufReader::new(file)) as Box) + } else { + // Probably file was renamed/moved or removed again + None + }; // Add new reader but keep old display name files.insert( new_path, PathData { - metadata: file.metadata().ok(), - reader: Some(Box::new(BufReader::new(file))), + metadata: new_path.metadata().ok(), + reader, display_name, // mimic GNU's tail and show old name in header }, files.get_last().unwrap() == event_path ); - // Remove old reader - files.remove(event_path); // Unwatch old path and watch new path let _ = watcher.unwatch(event_path); watcher.watch_with_parent(new_path)?; @@ -1103,8 +1110,8 @@ mod files { } /// Wrapper for HashMap::remove using Path::canonicalize - pub fn remove(&mut self, k: &Path) { - self.map.remove(&Self::canonicalize_path(k)).unwrap(); + pub fn remove(&mut self, k: &Path) -> PathData { + self.map.remove(&Self::canonicalize_path(k)).unwrap() } /// Wrapper for HashMap::get using Path::canonicalize From 0ed8b97a3f3eb8a0ee1cd992d7fa42e3db893517 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Wed, 17 Aug 2022 14:29:53 +0200 Subject: [PATCH 09/44] uucore: remove panic encoding handling We never want utilities to panic on invalid input and it is not currently in use, so it can be removed safely. --- src/uucore/src/lib/lib.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index d8860cfda..58893623d 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -153,7 +153,6 @@ pub fn execution_phrase() -> &'static str { pub enum InvalidEncodingHandling { Ignore, ConvertLossy, - Panic, } #[must_use] @@ -192,11 +191,9 @@ pub trait Args: Iterator + Sized { /// Converts each iterator item to a String and collects these into a vector /// On invalid encoding, the result will depend on the argument. This method allows to either drop entries with illegal encoding /// completely (```InvalidEncodingHandling::Ignore```), convert them using lossy-conversion (```InvalidEncodingHandling::ConvertLossy```) - /// which will result in strange strings or can chosen to panic (```InvalidEncodingHandling::Panic```). + /// which will result in strange strings or can chosen to panic. /// # Arguments /// * `handling` - This switch allows to switch the behavior, when invalid encoding is encountered - /// # Panics - /// * Occurs, when invalid encoding is encountered and handling is set to ```InvalidEncodingHandling::Panic``` fn collect_str(self, handling: InvalidEncodingHandling) -> ConversionResult { let mut full_conversion = true; let result_vector: Vec = self @@ -213,9 +210,6 @@ pub trait Args: Iterator + Sized { InvalidEncodingHandling::ConvertLossy => { Err(s_ret.to_string_lossy().into_owned()) } - InvalidEncodingHandling::Panic => { - panic!("Broken encoding found but caller cannot handle it") - } } } }) From 5621502a95e12b1542bf123730e7dc7cf1f23f19 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Wed, 17 Aug 2022 14:57:28 +0200 Subject: [PATCH 10/44] all: remove `accept_{any, complete, lossy}` and `ConversionResult` Outside of tests, only `accept_any` was used, meaning that this unnecessarily complicated the code. The behaviour of `accept_any` is now the default (and only) option. --- src/uu/base32/src/base_common.rs | 4 +- src/uu/basename/src/basename.rs | 4 +- src/uu/basenc/src/basenc.rs | 5 +- src/uu/cat/src/cat.rs | 4 +- src/uu/chmod/src/chmod.rs | 4 +- src/uu/chroot/src/chroot.rs | 4 +- src/uu/cksum/src/cksum.rs | 4 +- src/uu/comm/src/comm.rs | 4 +- src/uu/csplit/src/csplit.rs | 4 +- src/uu/cut/src/cut.rs | 4 +- src/uu/dd/src/dd.rs | 1 - src/uu/dircolors/src/dircolors.rs | 4 +- src/uu/dirname/src/dirname.rs | 4 +- src/uu/du/src/du.rs | 4 +- src/uu/echo/src/echo.rs | 4 +- src/uu/expand/src/expand.rs | 4 +- src/uu/expr/src/expr.rs | 4 +- src/uu/fold/src/fold.rs | 4 +- src/uu/kill/src/kill.rs | 4 +- src/uu/logname/src/logname.rs | 4 +- src/uu/mkdir/src/mkdir.rs | 4 +- src/uu/mkfifo/src/mkfifo.rs | 4 +- src/uu/mknod/src/mknod.rs | 4 +- src/uu/mktemp/src/mktemp.rs | 4 +- src/uu/nl/src/nl.rs | 4 +- src/uu/nohup/src/nohup.rs | 4 +- src/uu/numfmt/src/numfmt.rs | 4 +- src/uu/od/src/od.rs | 4 +- src/uu/pathchk/src/pathchk.rs | 4 +- src/uu/pinky/src/pinky.rs | 4 +- src/uu/pr/src/pr.rs | 4 +- src/uu/printf/src/printf.rs | 4 +- src/uu/ptx/src/ptx.rs | 4 +- src/uu/relpath/src/relpath.rs | 4 +- src/uu/shred/src/shred.rs | 4 +- src/uu/shuf/src/shuf.rs | 4 +- src/uu/sort/src/sort.rs | 4 +- src/uu/stdbuf/src/stdbuf.rs | 4 +- src/uu/sum/src/sum.rs | 4 +- src/uu/tac/src/tac.rs | 4 +- src/uu/timeout/src/timeout.rs | 4 +- src/uu/tr/src/tr.rs | 4 +- src/uu/tsort/src/tsort.rs | 4 +- src/uu/tty/src/tty.rs | 4 +- src/uu/unexpand/src/unexpand.rs | 4 +- src/uu/who/src/who.rs | 4 +- src/uucore/src/lib/lib.rs | 105 ++++++++---------------------- tests/common/util.rs | 3 +- 48 files changed, 74 insertions(+), 216 deletions(-) diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index d49f02bc8..41a9fcc6a 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -87,9 +87,7 @@ impl Config { pub fn parse_base_cmd_args(args: impl uucore::Args, about: &str, usage: &str) -> UResult { let command = base_app(about, usage); - let arg_list = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let arg_list = args.collect_str(InvalidEncodingHandling::ConvertLossy); Config::from(&command.try_get_matches_from(arg_list)?) } diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index b52717287..461dabb66 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -28,9 +28,7 @@ pub mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); // Since options have to go before names, // if the first argument is not an option, then there is no option, diff --git a/src/uu/basenc/src/basenc.rs b/src/uu/basenc/src/basenc.rs index 1ecacf936..9a4f19f2b 100644 --- a/src/uu/basenc/src/basenc.rs +++ b/src/uu/basenc/src/basenc.rs @@ -52,10 +52,7 @@ pub fn uu_app<'a>() -> Command<'a> { fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> { let matches = uu_app() - .try_get_matches_from( - args.collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(), - ) + .try_get_matches_from(args.collect_str(InvalidEncodingHandling::ConvertLossy)) .with_exit_code(1)?; let format = ENCODINGS .iter() diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index 62afc0aa3..584e1d735 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -184,9 +184,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().try_get_matches_from(args)?; diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index d1a051a1c..458f788b2 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -46,9 +46,7 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let mut args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let mut args = args.collect_str(InvalidEncodingHandling::ConvertLossy); // Before we can parse 'args' with clap (and previously getopts), // a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE"). diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 6f575f4b1..79f679561 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -33,9 +33,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index fd9796769..62d658969 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -114,9 +114,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index d553a87ca..5ba9b434f 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -132,9 +132,7 @@ fn open_file(name: &str) -> io::Result { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); let filename1 = matches.value_of(options::FILE_1).unwrap(); diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index fc60ec1ca..4f94020b6 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -713,9 +713,7 @@ mod tests { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 2d76648d0..f9319d0e8 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -398,9 +398,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let delimiter_is_equal = args.contains(&"-d=".to_string()); // special case let matches = uu_app().get_matches_from(args); diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 94da4b7d3..d60ad1e3c 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -707,7 +707,6 @@ fn append_dashes_if_not_present(mut acc: Vec, mut s: String) -> Vec UResult<()> { let dashed_args = args .collect_str(InvalidEncodingHandling::Ignore) - .accept_any() .into_iter() .fold(Vec::new(), append_dashes_if_not_present); diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 5a014eafe..04a9f6dd8 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -65,9 +65,7 @@ pub fn guess_syntax() -> OutputFmt { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().get_matches_from(&args); diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index 5b7fa3c56..670a4a589 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -28,9 +28,7 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let after_help = get_long_usage(); diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 22d229f83..649edcd8d 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -516,9 +516,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult> { #[uucore::main] #[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index f02f938f2..3904d6225 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -110,9 +110,7 @@ fn print_escaped(input: &str, mut output: impl Write) -> io::Result { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); let no_newline = matches.contains_id(options::NO_NEWLINE); diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 06d903679..f1ece7d0c 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -269,9 +269,7 @@ fn expand_shortcuts(args: &[String]) -> Vec { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().get_matches_from(expand_shortcuts(&args)); diff --git a/src/uu/expr/src/expr.rs b/src/uu/expr/src/expr.rs index 104398241..cf4e27d01 100644 --- a/src/uu/expr/src/expr.rs +++ b/src/uu/expr/src/expr.rs @@ -33,9 +33,7 @@ pub fn uu_app<'a>() -> Command<'a> { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); // For expr utility we do not want getopts. // The following usage should work without escaping hyphens: `expr -15 = 1 + 2 \* \( 3 - -4 \)` diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index 6484a56f9..b923e6fa7 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -31,9 +31,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let (args, obs_width) = handle_obsolete(&args[..]); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index 3c8f62d59..f7548dbed 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -38,9 +38,7 @@ pub enum Mode { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let mut args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let mut args = args.collect_str(InvalidEncodingHandling::Ignore); let obs_signal = handle_obsolete(&mut args); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/logname/src/logname.rs b/src/uu/logname/src/logname.rs index 29a74a373..5fe2181af 100644 --- a/src/uu/logname/src/logname.rs +++ b/src/uu/logname/src/logname.rs @@ -37,9 +37,7 @@ static ABOUT: &str = "Print user's login name"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let _ = uu_app().get_matches_from(args); diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 8a6d2e9dd..b6a13f2fc 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -83,9 +83,7 @@ fn strip_minus_from_mode(args: &mut Vec) -> bool { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let mut args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let mut args = args.collect_str(InvalidEncodingHandling::ConvertLossy); // Before we can parse 'args' with clap (and previously getopts), // a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE"). diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index 3530b5c9e..2e8d0c7b1 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -28,9 +28,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index cda500f65..1b6f8c5c5 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -81,9 +81,7 @@ fn _mknod(file_name: &str, mode: mode_t, dev: dev_t) -> i32 { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); // Linux-specific options, not implemented // opts.optflag("Z", "", "set the SELinux security context to default type"); // opts.optopt("", "context", "like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX"); diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 561281c72..ab0970f15 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -11,7 +11,7 @@ use clap::{crate_version, Arg, ArgMatches, Command}; use uucore::display::{println_verbatim, Quotable}; use uucore::error::{FromIo, UError, UResult}; -use uucore::format_usage; +use uucore::{format_usage, InvalidEncodingHandling}; use std::env; use std::error::Error; @@ -316,7 +316,7 @@ impl Params { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str_lossy().accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().try_get_matches_from(&args)?; diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 7cea6f80f..b9311adba 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -84,9 +84,7 @@ pub mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index 600dff388..2e4a45ec5 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -86,9 +86,7 @@ impl Display for NohupError { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index d259d001d..401b3348e 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -261,9 +261,7 @@ fn concat_format_arg_and_value(args: &[String]) -> Vec { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().get_matches_from(concat_format_arg_and_value(&args)); diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index bdbe78fc7..0666e9752 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -256,9 +256,7 @@ impl OdOptions { /// opens the input and calls `odfunc` to process the input. #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let clap_opts = uu_app(); diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index 53689e4ff..b8fe0c485 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -39,9 +39,7 @@ const POSIX_NAME_MAX: usize = 14; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index 6235566b1..e9fd28bd4 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -49,9 +49,7 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let after_help = get_long_usage(); diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index e062b6c7f..8112555f5 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -378,9 +378,7 @@ pub fn uu_app<'a>() -> Command<'a> { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(uucore::InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(uucore::InvalidEncodingHandling::Ignore); let opt_args = recreate_arguments(&args); diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index b0c3e0b50..b1b6d146e 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -271,9 +271,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().get_matches_from(args); let format_string = matches diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index cb593c356..8873607f4 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -722,9 +722,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); // let mut opts = Options::new(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/relpath/src/relpath.rs b/src/uu/relpath/src/relpath.rs index 1fd0f0680..aa54c5716 100644 --- a/src/uu/relpath/src/relpath.rs +++ b/src/uu/relpath/src/relpath.rs @@ -27,9 +27,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index e0ab886bb..7b08a09b1 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -266,9 +266,7 @@ pub mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 418924ec7..e4b1516ca 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -56,9 +56,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 5b2cbc714..d3ba90489 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1055,9 +1055,7 @@ fn make_sort_mode_arg<'a>(mode: &'a str, short: char, help: &'a str) -> Arg<'a> #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let mut settings: GlobalSettings = Default::default(); let matches = match uu_app().try_get_matches_from(args) { diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 49654c39a..72f923606 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -156,9 +156,7 @@ fn get_preload_env(tmp_dir: &mut TempDir) -> io::Result<(String, PathBuf)> { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 01758d90a..abd536900 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -109,9 +109,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index f6baed971..b9786123b 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -37,9 +37,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index 187294ba3..6c42b17eb 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -106,9 +106,7 @@ impl Config { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let command = uu_app(); diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 3208a7ee1..825188383 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -40,9 +40,7 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let after_help = get_long_usage(); diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index 056c2be8d..47fb05c83 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -25,9 +25,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index 953d6d954..4b492c50f 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -24,9 +24,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index 1b67785a2..f333f9c18 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -165,9 +165,7 @@ fn expand_shortcuts(args: &[String]) -> Vec { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let matches = uu_app().get_matches_from(expand_shortcuts(&args)); diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index a01cb0dda..76b01f850 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -56,9 +56,7 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + let args = args.collect_str(InvalidEncodingHandling::Ignore); let after_help = get_long_usage(); diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 58893623d..c6c3200ef 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -155,38 +155,6 @@ pub enum InvalidEncodingHandling { ConvertLossy, } -#[must_use] -pub enum ConversionResult { - Complete(Vec), - Lossy(Vec), -} - -impl ConversionResult { - pub fn accept_any(self) -> Vec { - match self { - Self::Complete(result) | Self::Lossy(result) => result, - } - } - - pub fn expect_lossy(self, msg: &str) -> Vec { - match self { - Self::Lossy(result) => result, - Self::Complete(_) => { - panic!("{}", msg); - } - } - } - - pub fn expect_complete(self, msg: &str) -> Vec { - match self { - Self::Complete(result) => result, - Self::Lossy(_) => { - panic!("{}", msg); - } - } - } -} - pub trait Args: Iterator + Sized { /// Converts each iterator item to a String and collects these into a vector /// On invalid encoding, the result will depend on the argument. This method allows to either drop entries with illegal encoding @@ -194,45 +162,31 @@ pub trait Args: Iterator + Sized { /// which will result in strange strings or can chosen to panic. /// # Arguments /// * `handling` - This switch allows to switch the behavior, when invalid encoding is encountered - fn collect_str(self, handling: InvalidEncodingHandling) -> ConversionResult { - let mut full_conversion = true; - let result_vector: Vec = self - .map(|s| match s.into_string() { - Ok(string) => Ok(string), - Err(s_ret) => { - full_conversion = false; - eprintln!( - "Input with broken encoding occurred! (s = {}) ", - s_ret.quote() - ); - match handling { - InvalidEncodingHandling::Ignore => Err(String::new()), - InvalidEncodingHandling::ConvertLossy => { - Err(s_ret.to_string_lossy().into_owned()) - } + fn collect_str(self, handling: InvalidEncodingHandling) -> Vec { + self.map(|s| match s.into_string() { + Ok(string) => Ok(string), + Err(s_ret) => { + eprintln!( + "Input with broken encoding occurred! (s = {}) ", + s_ret.quote() + ); + match handling { + InvalidEncodingHandling::Ignore => Err(String::new()), + InvalidEncodingHandling::ConvertLossy => { + Err(s_ret.to_string_lossy().into_owned()) } } - }) - .filter(|s| match handling { - InvalidEncodingHandling::Ignore => s.is_ok(), - _ => true, - }) - .map(|s| match s { - Ok(v) => v, - Err(e) => e, - }) - .collect(); - - if full_conversion { - ConversionResult::Complete(result_vector) - } else { - ConversionResult::Lossy(result_vector) - } - } - - /// convenience function for a more slim interface - fn collect_str_lossy(self) -> ConversionResult { - self.collect_str(InvalidEncodingHandling::ConvertLossy) + } + }) + .filter(|s| match handling { + InvalidEncodingHandling::Ignore => s.is_ok(), + _ => true, + }) + .map(|s| match s { + Ok(v) => v, + Err(e) => e, + }) + .collect() } } @@ -255,7 +209,7 @@ mod tests { ] } - fn collect_os_str(vec: Vec, handling: InvalidEncodingHandling) -> ConversionResult { + fn collect_os_str(vec: Vec, handling: InvalidEncodingHandling) -> Vec { vec.into_iter().collect_str(handling) } @@ -265,8 +219,7 @@ mod tests { assert!(os_str.to_os_string().into_string().is_err()); let test_vec = make_os_vec(os_str); let collected_to_str = - collect_os_str(test_vec.clone(), InvalidEncodingHandling::ConvertLossy) - .expect_lossy("Lossy conversion expected in this test: bad encoding entries should be converted as good as possible"); + collect_os_str(test_vec.clone(), InvalidEncodingHandling::ConvertLossy); //conservation of length - when accepting lossy conversion no arguments may be dropped assert_eq!(collected_to_str.len(), test_vec.len()); //first indices identical @@ -288,10 +241,7 @@ mod tests { //assert our string is invalid utf8 assert!(os_str.to_os_string().into_string().is_err()); let test_vec = make_os_vec(os_str); - let collected_to_str = collect_os_str(test_vec.clone(), InvalidEncodingHandling::Ignore) - .expect_lossy( - "Lossy conversion expected in this test: bad encoding entries should be filtered", - ); + let collected_to_str = collect_os_str(test_vec.clone(), InvalidEncodingHandling::Ignore); //assert that the broken entry is filtered out assert_eq!(collected_to_str.len(), test_vec.len() - 1); //assert that the unbroken indices are converted as expected @@ -308,8 +258,7 @@ mod tests { //create a vector containing only correct encoding let test_vec = make_os_vec(&OsString::from("test2")); //expect complete conversion without losses, even when lossy conversion is accepted - let _ = collect_os_str(test_vec, InvalidEncodingHandling::ConvertLossy) - .expect_complete("Lossy conversion not expected in this test"); + let _ = collect_os_str(test_vec, InvalidEncodingHandling::ConvertLossy); } #[cfg(any(unix, target_os = "redox"))] diff --git a/tests/common/util.rs b/tests/common/util.rs index 93c7e3d12..03876a570 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -1021,8 +1021,7 @@ impl UCommand { let strings = args .iter() .map(|s| s.as_ref().to_os_string()) - .collect_str(InvalidEncodingHandling::Ignore) - .accept_any(); + .collect_str(InvalidEncodingHandling::Ignore); for s in strings { self.comm_string.push(' '); From ba713b6365b4787af88211d36031f39c861428f2 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Wed, 17 Aug 2022 15:20:20 +0200 Subject: [PATCH 11/44] Simplify invalid encoding handling into two small methods of Args The previous encoding handling was unnecessarily complex. This commit removes the enum that specifies the handling and instead has two separate methods to collect the strings either with lossy conversion or by ignoring invalidly encoded strings. --- src/uu/base32/src/base_common.rs | 4 +- src/uu/basename/src/basename.rs | 4 +- src/uu/basenc/src/basenc.rs | 3 +- src/uu/cat/src/cat.rs | 4 +- src/uu/chmod/src/chmod.rs | 4 +- src/uu/chroot/src/chroot.rs | 4 +- src/uu/cksum/src/cksum.rs | 3 +- src/uu/comm/src/comm.rs | 4 +- src/uu/csplit/src/csplit.rs | 4 +- src/uu/cut/src/cut.rs | 4 +- src/uu/dd/src/dd.rs | 4 +- src/uu/dircolors/src/dircolors.rs | 4 +- src/uu/dirname/src/dirname.rs | 4 +- src/uu/du/src/du.rs | 3 +- src/uu/echo/src/echo.rs | 4 +- src/uu/expand/src/expand.rs | 4 +- src/uu/expr/src/expr.rs | 3 +- src/uu/fold/src/fold.rs | 4 +- src/uu/kill/src/kill.rs | 4 +- src/uu/logname/src/logname.rs | 3 +- src/uu/mkdir/src/mkdir.rs | 4 +- src/uu/mkfifo/src/mkfifo.rs | 4 +- src/uu/mknod/src/mknod.rs | 4 +- src/uu/mktemp/src/mktemp.rs | 4 +- src/uu/nl/src/nl.rs | 4 +- src/uu/nohup/src/nohup.rs | 4 +- src/uu/numfmt/src/numfmt.rs | 4 +- src/uu/od/src/od.rs | 3 +- src/uu/pathchk/src/pathchk.rs | 4 +- src/uu/pinky/src/pinky.rs | 4 +- src/uu/pr/src/pr.rs | 2 +- src/uu/printf/src/printf.rs | 3 +- src/uu/ptx/src/ptx.rs | 4 +- src/uu/relpath/src/relpath.rs | 4 +- src/uu/shred/src/shred.rs | 4 +- src/uu/shuf/src/shuf.rs | 4 +- src/uu/sort/src/sort.rs | 4 +- src/uu/stdbuf/src/stdbuf.rs | 4 +- src/uu/sum/src/sum.rs | 4 +- src/uu/tac/src/tac.rs | 3 +- src/uu/timeout/src/timeout.rs | 4 +- src/uu/tr/src/tr.rs | 4 +- src/uu/tsort/src/tsort.rs | 4 +- src/uu/tty/src/tty.rs | 4 +- src/uu/unexpand/src/unexpand.rs | 4 +- src/uu/who/src/who.rs | 4 +- src/uucore/src/lib/lib.rs | 82 +++++++++---------------------- tests/common/util.rs | 4 +- 48 files changed, 107 insertions(+), 153 deletions(-) diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index 41a9fcc6a..b535260c5 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -12,7 +12,7 @@ use std::io::{stdout, Read, Write}; use uucore::display::Quotable; use uucore::encoding::{wrap_print, Data, Format}; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; use std::fs::File; use std::io::{BufReader, Stdin}; @@ -87,7 +87,7 @@ impl Config { pub fn parse_base_cmd_args(args: impl uucore::Args, about: &str, usage: &str) -> UResult { let command = base_app(about, usage); - let arg_list = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let arg_list = args.collect_lossy(); Config::from(&command.try_get_matches_from(arg_list)?) } diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index 461dabb66..af961f5fb 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -11,7 +11,7 @@ use clap::{crate_version, Arg, Command}; use std::path::{is_separator, PathBuf}; use uucore::display::Quotable; use uucore::error::{UResult, UUsageError}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static ABOUT: &str = r#"Print NAME with any leading directory components removed If specified, also remove a trailing SUFFIX"#; @@ -28,7 +28,7 @@ pub mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); // Since options have to go before names, // if the first argument is not an option, then there is no option, diff --git a/src/uu/basenc/src/basenc.rs b/src/uu/basenc/src/basenc.rs index 9a4f19f2b..d884c04e3 100644 --- a/src/uu/basenc/src/basenc.rs +++ b/src/uu/basenc/src/basenc.rs @@ -14,7 +14,6 @@ use uu_base32::base_common::{self, Config, BASE_CMD_PARSE_ERROR}; use uucore::{ encoding::Format, error::{UResult, UUsageError}, - InvalidEncodingHandling, }; use std::io::{stdin, Read}; @@ -52,7 +51,7 @@ pub fn uu_app<'a>() -> Command<'a> { fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> { let matches = uu_app() - .try_get_matches_from(args.collect_str(InvalidEncodingHandling::ConvertLossy)) + .try_get_matches_from(args.collect_lossy()) .with_exit_code(1)?; let format = ENCODINGS .iter() diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index 584e1d735..602a340cb 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -36,7 +36,7 @@ use std::net::Shutdown; use std::os::unix::fs::FileTypeExt; #[cfg(unix)] use unix_socket::UnixStream; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static NAME: &str = "cat"; static USAGE: &str = "{} [OPTION]... [FILE]..."; @@ -184,7 +184,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().try_get_matches_from(args)?; diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index 458f788b2..181517fea 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -18,7 +18,7 @@ use uucore::fs::is_symlink; use uucore::libc::mode_t; #[cfg(not(windows))] use uucore::mode; -use uucore::{format_usage, show_error, InvalidEncodingHandling}; +use uucore::{format_usage, show_error}; static ABOUT: &str = "Change the mode of each FILE to MODE. With --reference, change the mode of each FILE to that of RFILE."; @@ -46,7 +46,7 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let mut args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let mut args = args.collect_lossy(); // Before we can parse 'args' with clap (and previously getopts), // a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE"). diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 79f679561..1e5f62d5f 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -17,7 +17,7 @@ use std::path::Path; use std::process; use uucore::error::{set_exit_code, UResult}; use uucore::libc::{self, chroot, setgid, setgroups, setuid}; -use uucore::{entries, format_usage, InvalidEncodingHandling}; +use uucore::{entries, format_usage}; static ABOUT: &str = "Run COMMAND with root directory set to NEWROOT."; static USAGE: &str = "{} [OPTION]... NEWROOT [COMMAND [ARG]...]"; @@ -33,7 +33,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 62d658969..2d8c930fe 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -12,7 +12,6 @@ use std::io::{self, stdin, BufReader, Read}; use std::path::Path; use uucore::display::Quotable; use uucore::error::{FromIo, UResult}; -use uucore::InvalidEncodingHandling; use uucore::{format_usage, show}; // NOTE: CRC_TABLE_LEN *must* be <= 256 as we cast 0..CRC_TABLE_LEN to u8 @@ -114,7 +113,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index 5ba9b434f..5e08613cd 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -13,7 +13,7 @@ use std::io::{self, stdin, BufRead, BufReader, Stdin}; use std::path::Path; use uucore::error::FromIo; use uucore::error::UResult; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; use clap::{crate_version, Arg, ArgMatches, Command}; @@ -132,7 +132,7 @@ fn open_file(name: &str) -> io::Result { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); let filename1 = matches.value_of(options::FILE_1).unwrap(); diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index 4f94020b6..143d2d2e8 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -16,7 +16,7 @@ use clap::{crate_version, Arg, ArgMatches, Command}; use regex::Regex; use uucore::display::Quotable; use uucore::error::{FromIo, UResult}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; mod csplit_error; mod patterns; @@ -713,7 +713,7 @@ mod tests { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index f9319d0e8..a1883adc5 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -19,8 +19,8 @@ use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; use self::searcher::Searcher; +use uucore::format_usage; use uucore::ranges::Range; -use uucore::{format_usage, InvalidEncodingHandling}; mod searcher; @@ -398,7 +398,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let delimiter_is_equal = args.contains(&"-d=".to_string()); // special case let matches = uu_app().get_matches_from(args); diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index d60ad1e3c..0f5948710 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -37,7 +37,7 @@ use clap::{crate_version, Arg, ArgMatches, Command}; use gcd::Gcd; use uucore::display::Quotable; use uucore::error::{FromIo, UResult}; -use uucore::{show_error, InvalidEncodingHandling}; +use uucore::show_error; const ABOUT: &str = "copy, and optionally convert, a file system resource"; const BUF_INIT_BYTE: u8 = 0xDD; @@ -706,7 +706,7 @@ fn append_dashes_if_not_present(mut acc: Vec, mut s: String) -> Vec UResult<()> { let dashed_args = args - .collect_str(InvalidEncodingHandling::Ignore) + .collect_ignore() .into_iter() .fold(Vec::new(), append_dashes_if_not_present); diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 04a9f6dd8..3224f07e1 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -65,7 +65,7 @@ pub fn guess_syntax() -> OutputFmt { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().get_matches_from(&args); @@ -276,7 +276,7 @@ enum ParseState { } use std::collections::HashMap; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; fn parse(lines: T, fmt: &OutputFmt, fp: &str) -> Result where diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index 670a4a589..ed3deb7aa 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -9,7 +9,7 @@ use clap::{crate_version, Arg, Command}; use std::path::Path; use uucore::display::print_verbatim; use uucore::error::{UResult, UUsageError}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static ABOUT: &str = "strip last component from file name"; const USAGE: &str = "{} [OPTION] NAME..."; @@ -28,7 +28,7 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let after_help = get_long_usage(); diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 649edcd8d..41a532ffd 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -39,7 +39,6 @@ use uucore::error::{UError, UResult}; use uucore::format_usage; use uucore::parse_glob; use uucore::parse_size::{parse_size, ParseSizeError}; -use uucore::InvalidEncodingHandling; #[cfg(windows)] use winapi::shared::minwindef::{DWORD, LPVOID}; #[cfg(windows)] @@ -516,7 +515,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult> { #[uucore::main] #[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index 3904d6225..6f4d2e674 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -11,7 +11,7 @@ use std::io::{self, Write}; use std::iter::Peekable; use std::str::Chars; use uucore::error::{FromIo, UResult}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; const NAME: &str = "echo"; const ABOUT: &str = "display a line of text"; @@ -110,7 +110,7 @@ fn print_escaped(input: &str, mut output: impl Write) -> io::Result { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); let no_newline = matches.contains_id(options::NO_NEWLINE); diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index f1ece7d0c..bbbe2de71 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -22,7 +22,7 @@ use std::str::from_utf8; use unicode_width::UnicodeWidthChar; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static ABOUT: &str = "Convert tabs in each FILE to spaces, writing to standard output. With no FILE, or when FILE is -, read standard input."; @@ -269,7 +269,7 @@ fn expand_shortcuts(args: &[String]) -> Vec { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().get_matches_from(expand_shortcuts(&args)); diff --git a/src/uu/expr/src/expr.rs b/src/uu/expr/src/expr.rs index cf4e27d01..9b4ec0b19 100644 --- a/src/uu/expr/src/expr.rs +++ b/src/uu/expr/src/expr.rs @@ -7,7 +7,6 @@ use clap::{crate_version, Arg, Command}; use uucore::error::{UResult, USimpleError}; -use uucore::InvalidEncodingHandling; mod syntax_tree; mod tokens; @@ -33,7 +32,7 @@ pub fn uu_app<'a>() -> Command<'a> { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); // For expr utility we do not want getopts. // The following usage should work without escaping hyphens: `expr -15 = 1 + 2 \* \( 3 - -4 \)` diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index b923e6fa7..6587d5eae 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -13,7 +13,7 @@ use std::io::{stdin, BufRead, BufReader, Read}; use std::path::Path; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; const TAB_WIDTH: usize = 8; @@ -31,7 +31,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let (args, obs_width) = handle_obsolete(&args[..]); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index f7548dbed..abb72799d 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -16,8 +16,8 @@ use nix::unistd::Pid; use std::io::Error; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult, USimpleError}; +use uucore::format_usage; use uucore::signals::{signal_by_name_or_value, ALL_SIGNALS}; -use uucore::{format_usage, InvalidEncodingHandling}; static ABOUT: &str = "Send signal to processes or list information about signals."; const USAGE: &str = "{} [OPTIONS]... PID..."; @@ -38,7 +38,7 @@ pub enum Mode { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let mut args = args.collect_str(InvalidEncodingHandling::Ignore); + let mut args = args.collect_ignore(); let obs_signal = handle_obsolete(&mut args); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/logname/src/logname.rs b/src/uu/logname/src/logname.rs index 5fe2181af..112923296 100644 --- a/src/uu/logname/src/logname.rs +++ b/src/uu/logname/src/logname.rs @@ -15,7 +15,6 @@ extern crate uucore; use clap::{crate_version, Command}; use std::ffi::CStr; use uucore::error::UResult; -use uucore::InvalidEncodingHandling; extern "C" { // POSIX requires using getlogin (or equivalent code) @@ -37,7 +36,7 @@ static ABOUT: &str = "Print user's login name"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let _ = uu_app().get_matches_from(args); diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index b6a13f2fc..3f7cbf1b9 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -15,10 +15,10 @@ use std::path::{Path, PathBuf}; #[cfg(not(windows))] use uucore::error::FromIo; use uucore::error::{UResult, USimpleError}; +use uucore::format_usage; #[cfg(not(windows))] use uucore::mode; use uucore::{display::Quotable, fs::dir_strip_dot_for_creation}; -use uucore::{format_usage, InvalidEncodingHandling}; static DEFAULT_PERM: u32 = 0o755; @@ -83,7 +83,7 @@ fn strip_minus_from_mode(args: &mut Vec) -> bool { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let mut args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let mut args = args.collect_lossy(); // Before we can parse 'args' with clap (and previously getopts), // a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE"). diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index 2e8d0c7b1..1c70f52c6 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -11,9 +11,9 @@ extern crate uucore; use clap::{crate_version, Arg, Command}; use libc::mkfifo; use std::ffi::CString; +use uucore::display::Quotable; use uucore::error::{UResult, USimpleError}; use uucore::format_usage; -use uucore::{display::Quotable, InvalidEncodingHandling}; static NAME: &str = "mkfifo"; static USAGE: &str = "{} [OPTION]... NAME..."; @@ -28,7 +28,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index 1b6f8c5c5..551d1e90d 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -15,7 +15,7 @@ use libc::{S_IFBLK, S_IFCHR, S_IFIFO, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOT use uucore::display::Quotable; use uucore::error::{set_exit_code, UResult, USimpleError, UUsageError}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static ABOUT: &str = "Create the special file NAME of the given TYPE."; static USAGE: &str = "{} [OPTION]... NAME TYPE [MAJOR MINOR]"; @@ -81,7 +81,7 @@ fn _mknod(file_name: &str, mode: mode_t, dev: dev_t) -> i32 { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); // Linux-specific options, not implemented // opts.optflag("Z", "", "set the SELinux security context to default type"); // opts.optopt("", "context", "like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX"); diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index ab0970f15..1131e0f01 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -11,7 +11,7 @@ use clap::{crate_version, Arg, ArgMatches, Command}; use uucore::display::{println_verbatim, Quotable}; use uucore::error::{FromIo, UError, UResult}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; use std::env; use std::error::Error; @@ -316,7 +316,7 @@ impl Params { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().try_get_matches_from(&args)?; diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index b9311adba..7f36cb424 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -14,7 +14,7 @@ use std::io::{stdin, BufRead, BufReader, Read}; use std::iter::repeat; use std::path::Path; use uucore::error::{FromIo, UResult, USimpleError}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; mod helper; @@ -84,7 +84,7 @@ pub mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index 2e4a45ec5..6b11ea920 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -22,7 +22,7 @@ use std::os::unix::prelude::*; use std::path::{Path, PathBuf}; use uucore::display::Quotable; use uucore::error::{set_exit_code, UError, UResult}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static ABOUT: &str = "Run COMMAND ignoring hangup signals."; static LONG_HELP: &str = " @@ -86,7 +86,7 @@ impl Display for NohupError { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 401b3348e..4139b6d31 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -16,8 +16,8 @@ use std::io::{BufRead, Write}; use units::{IEC_BASES, SI_BASES}; use uucore::display::Quotable; use uucore::error::UResult; +use uucore::format_usage; use uucore::ranges::Range; -use uucore::{format_usage, InvalidEncodingHandling}; pub mod errors; pub mod format; @@ -261,7 +261,7 @@ fn concat_format_arg_and_value(args: &[String]) -> Vec { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().get_matches_from(concat_format_arg_and_value(&args)); diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index 0666e9752..81068f0b7 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -48,7 +48,6 @@ use uucore::display::Quotable; use uucore::error::{UResult, USimpleError}; use uucore::format_usage; use uucore::parse_size::ParseSizeError; -use uucore::InvalidEncodingHandling; const PEEK_BUFFER_SIZE: usize = 4; // utf-8 can be 4 bytes static ABOUT: &str = "dump files in octal and other formats"; @@ -256,7 +255,7 @@ impl OdOptions { /// opens the input and calls `odfunc` to process the input. #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let clap_opts = uu_app(); diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index b8fe0c485..fb4d44494 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -13,7 +13,7 @@ use std::fs; use std::io::{ErrorKind, Write}; use uucore::display::Quotable; use uucore::error::{set_exit_code, UResult, UUsageError}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; // operating mode enum Mode { @@ -39,7 +39,7 @@ const POSIX_NAME_MAX: usize = 14; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index e9fd28bd4..039dd0a5e 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -20,7 +20,7 @@ use std::os::unix::fs::MetadataExt; use clap::{crate_version, Arg, Command}; use std::path::PathBuf; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static ABOUT: &str = "lightweight finger"; const USAGE: &str = "{} [OPTION]... [USER]..."; @@ -49,7 +49,7 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let after_help = get_long_usage(); diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 8112555f5..a27804fa6 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -378,7 +378,7 @@ pub fn uu_app<'a>() -> Command<'a> { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(uucore::InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let opt_args = recreate_arguments(&args); diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index b1b6d146e..e95e10cc8 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -4,7 +4,6 @@ use clap::{crate_version, Arg, Command}; use uucore::error::{UResult, UUsageError}; -use uucore::InvalidEncodingHandling; use uucore::{format_usage, memo}; const VERSION: &str = "version"; @@ -271,7 +270,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().get_matches_from(args); let format_string = matches diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 8873607f4..fc5820065 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -19,7 +19,7 @@ use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; use std::num::ParseIntError; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static NAME: &str = "ptx"; const USAGE: &str = "\ @@ -722,7 +722,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); // let mut opts = Options::new(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/relpath/src/relpath.rs b/src/uu/relpath/src/relpath.rs index aa54c5716..0e6051adb 100644 --- a/src/uu/relpath/src/relpath.rs +++ b/src/uu/relpath/src/relpath.rs @@ -12,8 +12,8 @@ use std::env; use std::path::{Path, PathBuf}; use uucore::display::println_verbatim; use uucore::error::{FromIo, UResult}; +use uucore::format_usage; use uucore::fs::{canonicalize, MissingHandling, ResolveMode}; -use uucore::{format_usage, InvalidEncodingHandling}; static ABOUT: &str = "Convert TO destination to the relative path from the FROM dir. If FROM path is omitted, current working dir will be used."; @@ -27,7 +27,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 7b08a09b1..8fa525482 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -20,7 +20,7 @@ use std::io::SeekFrom; use std::path::{Path, PathBuf}; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; -use uucore::{format_usage, util_name, InvalidEncodingHandling}; +use uucore::{format_usage, util_name}; #[macro_use] extern crate uucore; @@ -266,7 +266,7 @@ pub mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index e4b1516ca..50594cedb 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -15,7 +15,7 @@ use std::fs::File; use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write}; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; mod rand_read_adapter; @@ -56,7 +56,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index d3ba90489..25c6cd5b6 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -47,9 +47,9 @@ use std::str::Utf8Error; use unicode_width::UnicodeWidthStr; use uucore::display::Quotable; use uucore::error::{set_exit_code, strip_errno, UError, UResult, USimpleError, UUsageError}; +use uucore::format_usage; use uucore::parse_size::{parse_size, ParseSizeError}; use uucore::version_cmp::version_cmp; -use uucore::{format_usage, InvalidEncodingHandling}; use crate::tmp_dir::TmpDirWrapper; @@ -1055,7 +1055,7 @@ fn make_sort_mode_arg<'a>(mode: &'a str, short: char, help: &'a str) -> Arg<'a> #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let mut settings: GlobalSettings = Default::default(); let matches = match uu_app().try_get_matches_from(args) { diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 72f923606..a74091739 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -19,8 +19,8 @@ use std::process; use tempfile::tempdir; use tempfile::TempDir; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; +use uucore::format_usage; use uucore::parse_size::parse_size; -use uucore::{format_usage, InvalidEncodingHandling}; static ABOUT: &str = "Run COMMAND, with modified buffering operations for its standard streams.\n\n\ @@ -156,7 +156,7 @@ fn get_preload_env(tmp_dir: &mut TempDir) -> io::Result<(String, PathBuf)> { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index abd536900..1422e473b 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -16,7 +16,7 @@ use std::io::{stdin, Read}; use std::path::Path; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static NAME: &str = "sum"; static USAGE: &str = "{} [OPTION]... [FILE]..."; @@ -109,7 +109,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index b9786123b..924e30cfe 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -19,7 +19,6 @@ use std::{ use uucore::display::Quotable; use uucore::error::UError; use uucore::error::UResult; -use uucore::InvalidEncodingHandling; use uucore::{format_usage, show}; use crate::error::TacError; @@ -37,7 +36,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index 6c42b17eb..ed55780ef 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -20,9 +20,9 @@ use std::process::{self, Child, Stdio}; use std::time::Duration; use uucore::display::Quotable; use uucore::error::{UResult, USimpleError, UUsageError}; +use uucore::format_usage; use uucore::process::ChildExt; use uucore::signals::{signal_by_name_or_value, signal_name_by_value}; -use uucore::{format_usage, InvalidEncodingHandling}; static ABOUT: &str = "Start COMMAND, and kill it if still running after DURATION."; const USAGE: &str = "{} [OPTION] DURATION COMMAND..."; @@ -106,7 +106,7 @@ impl Config { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let command = uu_app(); diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 825188383..61ada1ab7 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -18,8 +18,8 @@ use std::io::{stdin, stdout, BufReader, BufWriter}; use uucore::{format_usage, show}; use crate::operation::DeleteOperation; +use uucore::display::Quotable; use uucore::error::{UResult, USimpleError, UUsageError}; -use uucore::{display::Quotable, InvalidEncodingHandling}; static ABOUT: &str = "translate or delete characters"; const USAGE: &str = "{} [OPTION]... SET1 [SET2]"; @@ -40,7 +40,7 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let after_help = get_long_usage(); diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index 47fb05c83..4aa9aca83 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -12,7 +12,7 @@ use std::io::{stdin, BufRead, BufReader, Read}; use std::path::Path; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static ABOUT: &str = "Topological sort the strings in FILE. Strings are defined as any sequence of tokens separated by whitespace (tab, space, or newline). @@ -25,7 +25,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index 4b492c50f..a8806703b 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -13,7 +13,7 @@ use clap::{crate_version, Arg, Command}; use std::ffi::CStr; use std::io::Write; use uucore::error::UResult; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static ABOUT: &str = "Print the file name of the terminal connected to standard input."; const USAGE: &str = "{} [OPTION]..."; @@ -24,7 +24,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::ConvertLossy); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index f333f9c18..e42bb11a3 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -21,7 +21,7 @@ use std::str::from_utf8; use unicode_width::UnicodeWidthChar; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; static NAME: &str = "unexpand"; static USAGE: &str = "{} [OPTION]... [FILE]..."; @@ -165,7 +165,7 @@ fn expand_shortcuts(args: &[String]) -> Vec { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let matches = uu_app().get_matches_from(expand_shortcuts(&args)); diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 76b01f850..a679609e7 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -18,7 +18,7 @@ use std::ffi::CStr; use std::fmt::Write; use std::os::unix::fs::MetadataExt; use std::path::PathBuf; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; mod options { pub const ALL: &str = "all"; @@ -56,7 +56,7 @@ fn get_long_usage() -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_str(InvalidEncodingHandling::Ignore); + let args = args.collect_ignore(); let after_help = get_long_usage(); diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index c6c3200ef..e216b8fe3 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -82,8 +82,6 @@ use std::sync::atomic::Ordering; use once_cell::sync::Lazy; -use crate::display::Quotable; - #[macro_export] macro_rules! bin { ($util:ident) => { @@ -150,43 +148,15 @@ pub fn execution_phrase() -> &'static str { &EXECUTION_PHRASE } -pub enum InvalidEncodingHandling { - Ignore, - ConvertLossy, -} - pub trait Args: Iterator + Sized { - /// Converts each iterator item to a String and collects these into a vector - /// On invalid encoding, the result will depend on the argument. This method allows to either drop entries with illegal encoding - /// completely (```InvalidEncodingHandling::Ignore```), convert them using lossy-conversion (```InvalidEncodingHandling::ConvertLossy```) - /// which will result in strange strings or can chosen to panic. - /// # Arguments - /// * `handling` - This switch allows to switch the behavior, when invalid encoding is encountered - fn collect_str(self, handling: InvalidEncodingHandling) -> Vec { - self.map(|s| match s.into_string() { - Ok(string) => Ok(string), - Err(s_ret) => { - eprintln!( - "Input with broken encoding occurred! (s = {}) ", - s_ret.quote() - ); - match handling { - InvalidEncodingHandling::Ignore => Err(String::new()), - InvalidEncodingHandling::ConvertLossy => { - Err(s_ret.to_string_lossy().into_owned()) - } - } - } - }) - .filter(|s| match handling { - InvalidEncodingHandling::Ignore => s.is_ok(), - _ => true, - }) - .map(|s| match s { - Ok(v) => v, - Err(e) => e, - }) - .collect() + /// Collects the iterator into a `Vec`, lossily converting the `OsString`s to `Strings`. + fn collect_lossy(self) -> Vec { + self.map(|s| s.to_string_lossy().into_owned()).collect() + } + + /// Collects the iterator into a `Vec`, removing any elements that contain invalid encoding. + fn collect_ignore(self) -> Vec { + self.filter_map(|s| s.into_string().ok()).collect() } } @@ -209,42 +179,34 @@ mod tests { ] } - fn collect_os_str(vec: Vec, handling: InvalidEncodingHandling) -> Vec { - vec.into_iter().collect_str(handling) - } - #[cfg(any(unix, target_os = "redox"))] fn test_invalid_utf8_args_lossy(os_str: &OsStr) { - //assert our string is invalid utf8 + // assert our string is invalid utf8 assert!(os_str.to_os_string().into_string().is_err()); let test_vec = make_os_vec(os_str); - let collected_to_str = - collect_os_str(test_vec.clone(), InvalidEncodingHandling::ConvertLossy); - //conservation of length - when accepting lossy conversion no arguments may be dropped + let collected_to_str = test_vec.clone().into_iter().collect_lossy(); + // conservation of length - when accepting lossy conversion no arguments may be dropped assert_eq!(collected_to_str.len(), test_vec.len()); - //first indices identical + // first indices identical for index in 0..2 { - assert_eq!( - collected_to_str.get(index).unwrap(), - test_vec.get(index).unwrap().to_str().unwrap() - ); + assert_eq!(collected_to_str[index], test_vec[index].to_str().unwrap()); } - //lossy conversion for string with illegal encoding is done + // lossy conversion for string with illegal encoding is done assert_eq!( - *collected_to_str.get(2).unwrap(), + *collected_to_str[2], os_str.to_os_string().to_string_lossy() ); } #[cfg(any(unix, target_os = "redox"))] fn test_invalid_utf8_args_ignore(os_str: &OsStr) { - //assert our string is invalid utf8 + // assert our string is invalid utf8 assert!(os_str.to_os_string().into_string().is_err()); let test_vec = make_os_vec(os_str); - let collected_to_str = collect_os_str(test_vec.clone(), InvalidEncodingHandling::Ignore); - //assert that the broken entry is filtered out + let collected_to_str = test_vec.clone().into_iter().collect_ignore(); + // assert that the broken entry is filtered out assert_eq!(collected_to_str.len(), test_vec.len() - 1); - //assert that the unbroken indices are converted as expected + // assert that the unbroken indices are converted as expected for index in 0..2 { assert_eq!( collected_to_str.get(index).unwrap(), @@ -255,10 +217,10 @@ mod tests { #[test] fn valid_utf8_encoding_args() { - //create a vector containing only correct encoding + // create a vector containing only correct encoding let test_vec = make_os_vec(&OsString::from("test2")); - //expect complete conversion without losses, even when lossy conversion is accepted - let _ = collect_os_str(test_vec, InvalidEncodingHandling::ConvertLossy); + // expect complete conversion without losses, even when lossy conversion is accepted + let _ = test_vec.into_iter().collect_lossy(); } #[cfg(any(unix, target_os = "redox"))] diff --git a/tests/common/util.rs b/tests/common/util.rs index 03876a570..46bf4d85e 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -30,7 +30,7 @@ use std::rc::Rc; use std::thread::sleep; use std::time::Duration; use tempfile::TempDir; -use uucore::{Args, InvalidEncodingHandling}; +use uucore::Args; #[cfg(windows)] static PROGNAME: &str = concat!(env!("CARGO_PKG_NAME"), ".exe"); @@ -1021,7 +1021,7 @@ impl UCommand { let strings = args .iter() .map(|s| s.as_ref().to_os_string()) - .collect_str(InvalidEncodingHandling::Ignore); + .collect_ignore(); for s in strings { self.comm_string.push(' '); From e465d0520f35983086bfc05f5a02dbaa090bb8cd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 17 Aug 2022 16:20:25 +0000 Subject: [PATCH 12/44] build(deps): bump once_cell from 1.13.0 to 1.13.1 Bumps [once_cell](https://github.com/matklad/once_cell) from 1.13.0 to 1.13.1. - [Release notes](https://github.com/matklad/once_cell/releases) - [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md) - [Commits](https://github.com/matklad/once_cell/compare/v1.13.0...v1.13.1) --- updated-dependencies: - dependency-name: once_cell dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/uu/ls/Cargo.toml | 2 +- src/uucore/Cargo.toml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba035a72c..3c7c62811 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1319,9 +1319,9 @@ checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" [[package]] name = "once_cell" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" [[package]] name = "onig" diff --git a/Cargo.toml b/Cargo.toml index 134f73925..455d45c8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -261,7 +261,7 @@ uudoc = [ "zip" ] [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } clap_complete = "3.1" -once_cell = "1.13.0" +once_cell = "1.13.1" phf = "0.10.1" selinux = { version="0.2", optional = true } textwrap = { version="0.15", features=["terminal_size"] } diff --git a/src/uu/ls/Cargo.toml b/src/uu/ls/Cargo.toml index 98cf83547..e23828459 100644 --- a/src/uu/ls/Cargo.toml +++ b/src/uu/ls/Cargo.toml @@ -24,7 +24,7 @@ termsize = "0.1.6" glob = "0.3.0" lscolors = { version = "0.11.0", features = ["ansi_term"] } uucore = { version = ">=0.0.8", package = "uucore", path = "../../uucore", features = ["entries", "fs"] } -once_cell = "1.13.0" +once_cell = "1.13.1" atty = "0.2" selinux = { version="0.2", optional = true } diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index d6f944751..73ee31138 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -33,7 +33,7 @@ data-encoding = { version="2.1", optional=true } data-encoding-macro = { version="0.1.12", optional=true } z85 = { version="3.0.5", optional=true } libc = { version="0.2.126", optional=true } -once_cell = "1.13.0" +once_cell = "1.13.1" os_display = "0.1.3" [target.'cfg(unix)'.dependencies] From 37b7375dae81ebe3a474b684526dac6ebdff23d6 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Wed, 17 Aug 2022 22:09:56 +0300 Subject: [PATCH 13/44] CI: add timeout to freebsd and android tests, since it sometimes hangs --- .github/workflows/CICD.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 96ab83c83..1f4bf590e 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -849,6 +849,7 @@ jobs: name: Test Android builds needs: [ min_version, deps ] runs-on: macos-latest + timeout-minutes: 90 strategy: fail-fast: false matrix: @@ -904,6 +905,7 @@ jobs: name: Tests/FreeBSD test suite needs: [ min_version, deps ] runs-on: ${{ matrix.job.os }} + timeout-minutes: 90 strategy: fail-fast: false matrix: From f255c0cae8eaed48aaf59f4e2527f2f026ed5fb9 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Wed, 17 Aug 2022 22:33:32 +0200 Subject: [PATCH 14/44] dir & vdir: fix docs not showing up on the website uudoc was getting a dummy clap app to generate documentation from. Now the app from ls is returned instead, so that it actually shows something. --- src/uu/dir/src/dir.rs | 6 +++--- src/uu/vdir/src/vdir.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/uu/dir/src/dir.rs b/src/uu/dir/src/dir.rs index 3e2d1d380..2f51395f2 100644 --- a/src/uu/dir/src/dir.rs +++ b/src/uu/dir/src/dir.rs @@ -13,7 +13,7 @@ use uucore::quoting_style::{Quotes, QuotingStyle}; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let command = uu_ls::uu_app(); + let command = uu_app(); let matches = command.get_matches_from(args); @@ -64,7 +64,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // To avoid code duplication, we reuse ls uu_app function which has the same // arguments. However, coreutils won't compile if one of the utils is missing -// an uu_app function, so we need this dummy one. +// an uu_app function, so we return the `ls` app. pub fn uu_app<'a>() -> Command<'a> { - Command::new(uucore::util_name()) + uu_ls::uu_app() } diff --git a/src/uu/vdir/src/vdir.rs b/src/uu/vdir/src/vdir.rs index 7f7ac2740..96ba5d53d 100644 --- a/src/uu/vdir/src/vdir.rs +++ b/src/uu/vdir/src/vdir.rs @@ -13,7 +13,7 @@ use uucore::quoting_style::{Quotes, QuotingStyle}; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let command = uu_ls::uu_app(); + let command = uu_app(); let matches = command.get_matches_from(args); let mut default_quoting_style = false; @@ -64,5 +64,5 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // arguments. However, coreutils won't compile if one of the utils is missing // an uu_app function, so we need this dummy one. pub fn uu_app<'a>() -> Command<'a> { - Command::new(uucore::util_name()) + uu_ls::uu_app() } From 791fb98dcc7517ccb82849fbf40c58a8c09abd2f Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Wed, 17 Aug 2022 21:03:36 +0200 Subject: [PATCH 15/44] tty: move from libc to nix This moves the unsafe from our responsibility to nix and makes the code a bit cleaner. --- Cargo.lock | 2 +- src/uu/tty/Cargo.toml | 2 +- src/uu/tty/src/tty.rs | 53 ++++++++++++++++++++----------------------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba035a72c..f68054b80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3030,7 +3030,7 @@ version = "0.0.14" dependencies = [ "atty", "clap 3.2.17", - "libc", + "nix", "uucore", ] diff --git a/src/uu/tty/Cargo.toml b/src/uu/tty/Cargo.toml index 7f5a7b059..65bfbf405 100644 --- a/src/uu/tty/Cargo.toml +++ b/src/uu/tty/Cargo.toml @@ -16,7 +16,7 @@ path = "src/tty.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +nix = "0.25" atty = "0.2" uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["fs"] } diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index a8806703b..98c89f8a7 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -10,9 +10,9 @@ // spell-checker:ignore (ToDO) ttyname filedesc use clap::{crate_version, Arg, Command}; -use std::ffi::CStr; use std::io::Write; -use uucore::error::UResult; +use std::os::unix::io::AsRawFd; +use uucore::error::{set_exit_code, UResult}; use uucore::format_usage; static ABOUT: &str = "Print the file name of the terminal connected to standard input."; @@ -24,42 +24,39 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args.collect_lossy(); - let matches = uu_app().get_matches_from(args); let silent = matches.contains_id(options::SILENT); - // Call libc function ttyname - let tty = unsafe { - let ptr = libc::ttyname(libc::STDIN_FILENO); - if !ptr.is_null() { - String::from_utf8_lossy(CStr::from_ptr(ptr).to_bytes()).to_string() + // If silent, we don't need the name, only whether or not stdin is a tty. + if silent { + return if atty::is(atty::Stream::Stdin) { + Ok(()) } else { - "".to_owned() - } + Err(1.into()) + }; }; let mut stdout = std::io::stdout(); - if !silent { - let write_result = if !tty.chars().all(|c| c.is_whitespace()) { - writeln!(stdout, "{}", tty) - } else { - writeln!(stdout, "not a tty") - }; - if write_result.is_err() || stdout.flush().is_err() { - // Don't return to prevent a panic later when another flush is attempted - // because the `uucore_procs::main` macro inserts a flush after execution for every utility. - std::process::exit(3); - } - } + // Get the ttyname via nix + let name = nix::unistd::ttyname(std::io::stdin().as_raw_fd()); - if atty::is(atty::Stream::Stdin) { - Ok(()) - } else { - Err(libc::EXIT_FAILURE.into()) - } + let write_result = match name { + Ok(name) => writeln!(stdout, "{}", name.display()), + Err(_) => { + set_exit_code(1); + writeln!(stdout, "not a tty") + } + }; + + if write_result.is_err() || stdout.flush().is_err() { + // Don't return to prevent a panic later when another flush is attempted + // because the `uucore_procs::main` macro inserts a flush after execution for every utility. + std::process::exit(3); + }; + + Ok(()) } pub fn uu_app<'a>() -> Command<'a> { From b983355bc406ad21f70f953a0f476209d50fb0af Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Wed, 17 Aug 2022 19:49:01 +0200 Subject: [PATCH 16/44] uucore & cp: remove `show_error_custom_description` macros `show_usage_error` --- src/uu/cp/src/cp.rs | 8 +++--- src/uucore/src/lib/macros.rs | 47 +----------------------------------- 2 files changed, 6 insertions(+), 49 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index a81d52ed8..6df240382 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -46,7 +46,7 @@ use std::path::{Path, PathBuf, StripPrefixError}; use std::str::FromStr; use std::string::ToString; use uucore::backup_control::{self, BackupMode}; -use uucore::error::{set_exit_code, ExitCode, UClapError, UError, UResult}; +use uucore::error::{set_exit_code, UClapError, UError, UResult, UUsageError}; use uucore::fs::{canonicalize, is_symlink, MissingHandling, ResolveMode}; use walkdir::WalkDir; @@ -498,8 +498,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let options = Options::from_matches(&matches)?; if options.overwrite == OverwriteMode::NoClobber && options.backup != BackupMode::NoBackup { - show_usage_error!("options --backup and --no-clobber are mutually exclusive"); - return Err(ExitCode(EXIT_ERR).into()); + return Err(UUsageError::new( + EXIT_ERR, + "options --backup and --no-clobber are mutually exclusive", + )); } let paths: Vec = matches diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index cdb3affb5..612160e19 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -25,7 +25,7 @@ //! - Print errors //! - From types implementing [`crate::error::UError`]: [`show!`], //! [`show_if_err!`] -//! - From custom messages: [`show_error!`], [`show_usage_error!`] +//! - From custom messages: [`show_error!`] //! - Print warnings: [`show_warning!`] //! - Terminate util execution //! - Crash program: [`crash!`], [`crash_if_err!`] @@ -155,26 +155,6 @@ macro_rules! show_error( }) ); -/// Show a warning to stderr in a similar style to GNU coreutils. -/// -/// Is this really required? Used in the following locations: -/// -/// ./src/uu/head/src/head.rs:12 -/// ./src/uu/head/src/head.rs:424 -/// ./src/uu/head/src/head.rs:427 -/// ./src/uu/head/src/head.rs:430 -/// ./src/uu/head/src/head.rs:453 -/// ./src/uu/du/src/du.rs:339 -/// ./src/uu/wc/src/wc.rs:270 -/// ./src/uu/wc/src/wc.rs:273 -#[macro_export] -macro_rules! show_error_custom_description ( - ($err:expr,$($args:tt)+) => ({ - eprint!("{}: {}: ", $crate::util_name(), $err); - eprintln!($($args)+); - }) -); - /// Print a warning message to stderr. /// /// Takes [`format!`]-compatible input and prepends it with the current @@ -198,31 +178,6 @@ macro_rules! show_warning( }) ); -/// Show a bad invocation help message in a similar style to GNU coreutils. -/// -/// Takes a [`format!`]-compatible input and prepends it with the current -/// utility's name before printing to stderr. -/// -/// # Examples -/// -/// ``` -/// # #[macro_use] -/// # extern crate uucore; -/// # fn main() { -/// // outputs : Couldn't apply foo to bar -/// // Try ' --help' for more information. -/// show_usage_error!("Couldn't apply {} to {}", "foo", "bar"); -/// # } -/// ``` -#[macro_export] -macro_rules! show_usage_error( - ($($args:tt)+) => ({ - eprint!("{}: ", $crate::util_name()); - eprintln!($($args)+); - eprintln!("Try '{} --help' for more information.", $crate::execution_phrase()); - }) -); - /// Display an error and [`std::process::exit`] /// /// Displays the provided error message using [`show_error!`], then invokes From 600cab0bd8e6ed55e7f0ab091796db098063197f Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 24 Jun 2022 20:01:02 +0200 Subject: [PATCH 17/44] starting work on stty --- Cargo.lock | 10 ++ Cargo.toml | 2 + src/uu/stty/Cargo.toml | 24 +++ src/uu/stty/LICENSE | 1 + src/uu/stty/src/flags.rs | 332 +++++++++++++++++++++++++++++++++++++++ src/uu/stty/src/main.rs | 1 + src/uu/stty/src/stty.rs | 240 ++++++++++++++++++++++++++++ 7 files changed, 610 insertions(+) create mode 100644 src/uu/stty/Cargo.toml create mode 120000 src/uu/stty/LICENSE create mode 100644 src/uu/stty/src/flags.rs create mode 100644 src/uu/stty/src/main.rs create mode 100644 src/uu/stty/src/stty.rs diff --git a/Cargo.lock b/Cargo.lock index ba035a72c..3c37e0ce6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -445,6 +445,7 @@ dependencies = [ "uu_split", "uu_stat", "uu_stdbuf", + "uu_stty", "uu_sum", "uu_sync", "uu_tac", @@ -2908,6 +2909,15 @@ dependencies = [ "uucore", ] +[[package]] +name = "uu_stty" +version = "0.0.14" +dependencies = [ + "clap 3.1.18", + "nix", + "uucore", +] + [[package]] name = "uu_sum" version = "0.0.14" diff --git a/Cargo.toml b/Cargo.toml index 134f73925..4d71d2c51 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -190,6 +190,7 @@ feat_require_unix = [ "nohup", "pathchk", "stat", + "stty", "timeout", "tty", "uname", @@ -348,6 +349,7 @@ sort = { optional=true, version="0.0.14", package="uu_sort", path="src/uu/so split = { optional=true, version="0.0.14", package="uu_split", path="src/uu/split" } stat = { optional=true, version="0.0.14", package="uu_stat", path="src/uu/stat" } stdbuf = { optional=true, version="0.0.14", package="uu_stdbuf", path="src/uu/stdbuf" } +stty = { optional=true, version="0.0.14", package="uu_stty", path="src/uu/stty" } sum = { optional=true, version="0.0.14", package="uu_sum", path="src/uu/sum" } sync = { optional=true, version="0.0.14", package="uu_sync", path="src/uu/sync" } tac = { optional=true, version="0.0.14", package="uu_tac", path="src/uu/tac" } diff --git a/src/uu/stty/Cargo.toml b/src/uu/stty/Cargo.toml new file mode 100644 index 000000000..d39786494 --- /dev/null +++ b/src/uu/stty/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "uu_stty" +version = "0.0.14" +authors = ["uutils developers"] +license = "MIT" +description = "stty ~ (uutils) print or change terminal characteristics" + +homepage = "https://github.com/uutils/coreutils" +repository = "https://github.com/uutils/coreutils/tree/main/src/uu/stty" +keywords = ["coreutils", "uutils", "cross-platform", "cli", "utility"] +categories = ["command-line-utilities"] +edition = "2021" + +[lib] +path = "src/stty.rs" + +[dependencies] +clap = { version = "3.1", features = ["wrap_help", "cargo"] } +uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } +nix = { version="0.24.1", features = ["term"] } + +[[bin]] +name = "stty" +path = "src/main.rs" diff --git a/src/uu/stty/LICENSE b/src/uu/stty/LICENSE new file mode 120000 index 000000000..5853aaea5 --- /dev/null +++ b/src/uu/stty/LICENSE @@ -0,0 +1 @@ +../../../LICENSE \ No newline at end of file diff --git a/src/uu/stty/src/flags.rs b/src/uu/stty/src/flags.rs new file mode 100644 index 000000000..b2688cb8d --- /dev/null +++ b/src/uu/stty/src/flags.rs @@ -0,0 +1,332 @@ +// * This file is part of the uutils coreutils package. +// * +// * For the full copyright and license information, please view the LICENSE file +// * that was distributed with this source code. + +// spell-checker:ignore parenb parodd cmspar hupcl cstopb cread clocal crtscts +// spell-checker:ignore ignbrk brkint ignpar parmrk inpck istrip inlcr igncr icrnl ixoff ixon iuclc ixany imaxbel iutf +// spell-checker:ignore opost olcuc ocrnl onlcr onocr onlret ofill ofdel +// spell-checker:ignore isig icanon iexten echoe crterase echok echonl noflsh xcase tostop echoprt prterase echoctl ctlecho echoke crtkill flusho extproc + +use crate::Flag; +use nix::sys::termios::{ControlFlags, InputFlags, LocalFlags, OutputFlags}; + +pub const CONTROL_FLAGS: [Flag; 8] = [ + Flag { + name: "parenb", + flag: ControlFlags::PARENB, + show: true, + sane: false, + }, + Flag { + name: "parodd", + flag: ControlFlags::PARODD, + show: true, + sane: false, + }, + Flag { + name: "cmspar", + flag: ControlFlags::CMSPAR, + show: true, + sane: false, + }, + Flag { + name: "hupcl", + flag: ControlFlags::HUPCL, + show: true, + sane: true, + }, + Flag { + name: "cstopb", + flag: ControlFlags::CSTOPB, + show: true, + sane: false, + }, + Flag { + name: "cread", + flag: ControlFlags::CREAD, + show: true, + sane: true, + }, + Flag { + name: "clocal", + flag: ControlFlags::CLOCAL, + show: true, + sane: false, + }, + Flag { + name: "crtscts", + flag: ControlFlags::CRTSCTS, + show: true, + sane: false, + }, +]; + +pub const INPUT_FLAGS: [Flag; 15] = [ + Flag { + name: "ignbrk", + flag: InputFlags::IGNBRK, + show: true, + sane: false, + }, + Flag { + name: "brkint", + flag: InputFlags::BRKINT, + show: true, + sane: true, + }, + Flag { + name: "ignpar", + flag: InputFlags::IGNPAR, + show: true, + sane: false, + }, + Flag { + name: "parmrk", + flag: InputFlags::PARMRK, + show: true, + sane: false, + }, + Flag { + name: "inpck", + flag: InputFlags::INPCK, + show: true, + sane: false, + }, + Flag { + name: "istrip", + flag: InputFlags::ISTRIP, + show: true, + sane: false, + }, + Flag { + name: "inlcr", + flag: InputFlags::INLCR, + show: true, + sane: false, + }, + Flag { + name: "igncr", + flag: InputFlags::IGNCR, + show: true, + sane: false, + }, + Flag { + name: "icrnl", + flag: InputFlags::ICRNL, + show: true, + sane: true, + }, + Flag { + name: "ixoff", + flag: InputFlags::IXOFF, + show: true, + sane: false, + }, + Flag { + name: "tandem", + flag: InputFlags::IXOFF, + show: false, + sane: false, + }, + Flag { + name: "ixon", + flag: InputFlags::IXON, + show: true, + sane: false, + }, + // not supported by nix + // Flag { + // name: "iuclc", + // flag: InputFlags::IUCLC, + // show: true, + // default: false, + // }, + Flag { + name: "ixany", + flag: InputFlags::IXANY, + show: true, + sane: false, + }, + Flag { + name: "imaxbel", + flag: InputFlags::IMAXBEL, + show: true, + sane: true, + }, + Flag { + name: "iutf8", + flag: InputFlags::IUTF8, + show: true, + sane: false, + }, +]; + +pub const OUTPUT_FLAGS: [Flag; 8] = [ + Flag { + name: "opost", + flag: OutputFlags::OPOST, + show: true, + sane: true, + }, + Flag { + name: "olcuc", + flag: OutputFlags::OLCUC, + show: true, + sane: false, + }, + Flag { + name: "ocrnl", + flag: OutputFlags::OCRNL, + show: true, + sane: false, + }, + Flag { + name: "onlcr", + flag: OutputFlags::ONLCR, + show: true, + sane: true, + }, + Flag { + name: "onocr", + flag: OutputFlags::ONOCR, + show: true, + sane: false, + }, + Flag { + name: "onlret", + flag: OutputFlags::ONLRET, + show: true, + sane: false, + }, + Flag { + name: "ofill", + flag: OutputFlags::OFILL, + show: true, + sane: false, + }, + Flag { + name: "ofdel", + flag: OutputFlags::OFDEL, + show: true, + sane: false, + }, +]; + +pub const LOCAL_FLAGS: [Flag; 18] = [ + Flag { + name: "isig", + flag: LocalFlags::ISIG, + show: true, + sane: true, + }, + Flag { + name: "icanon", + flag: LocalFlags::ICANON, + show: true, + sane: true, + }, + Flag { + name: "iexten", + flag: LocalFlags::IEXTEN, + show: true, + sane: true, + }, + Flag { + name: "echo", + flag: LocalFlags::ECHO, + show: true, + sane: true, + }, + Flag { + name: "echoe", + flag: LocalFlags::ECHOE, + show: true, + sane: true, + }, + Flag { + name: "crterase", + flag: LocalFlags::ECHOE, + show: false, + sane: true, + }, + Flag { + name: "echok", + flag: LocalFlags::ECHOK, + show: true, + sane: true, + }, + Flag { + name: "echonl", + flag: LocalFlags::ECHONL, + show: true, + sane: false, + }, + Flag { + name: "noflsh", + flag: LocalFlags::NOFLSH, + show: true, + sane: false, + }, + // Not supported by nix + // Flag { + // name: "xcase", + // flag: LocalFlags::XCASE, + // show: true, + // sane: false, + // }, + Flag { + name: "tostop", + flag: LocalFlags::TOSTOP, + show: true, + sane: false, + }, + Flag { + name: "echoprt", + flag: LocalFlags::ECHOPRT, + show: true, + sane: false, + }, + Flag { + name: "prterase", + flag: LocalFlags::ECHOPRT, + show: false, + sane: false, + }, + Flag { + name: "echoctl", + flag: LocalFlags::ECHOCTL, + show: true, + sane: true, + }, + Flag { + name: "ctlecho", + flag: LocalFlags::ECHOCTL, + show: false, + sane: true, + }, + Flag { + name: "echoke", + flag: LocalFlags::ECHOKE, + show: true, + sane: true, + }, + Flag { + name: "crtkill", + flag: LocalFlags::ECHOKE, + show: false, + sane: true, + }, + Flag { + name: "flusho", + flag: LocalFlags::FLUSHO, + show: true, + sane: false, + }, + Flag { + name: "extproc", + flag: LocalFlags::EXTPROC, + show: true, + sane: false, + }, +]; diff --git a/src/uu/stty/src/main.rs b/src/uu/stty/src/main.rs new file mode 100644 index 000000000..4f9b9799a --- /dev/null +++ b/src/uu/stty/src/main.rs @@ -0,0 +1 @@ +uucore::bin!(uu_stty); diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs new file mode 100644 index 000000000..52cd5995b --- /dev/null +++ b/src/uu/stty/src/stty.rs @@ -0,0 +1,240 @@ +// * This file is part of the uutils coreutils package. +// * +// * For the full copyright and license information, please view the LICENSE file +// * that was distributed with this source code. + +// spell-checker:ignore tcgetattr tcsetattr tcsanow + +mod flags; + +use clap::{crate_version, Arg, ArgMatches, Command}; +use nix::sys::termios::{ + tcgetattr, tcsetattr, ControlFlags, InputFlags, LocalFlags, OutputFlags, Termios, +}; +use std::io::{self, stdout}; +use std::os::unix::io::{AsRawFd, RawFd}; +use uucore::error::UResult; +use uucore::{format_usage, InvalidEncodingHandling}; + +use flags::{CONTROL_FLAGS, INPUT_FLAGS, LOCAL_FLAGS, OUTPUT_FLAGS}; + +const NAME: &str = "stty"; +const USAGE: &str = "\ +{} [-F DEVICE | --file=DEVICE] [SETTING]... +{} [-F DEVICE | --file=DEVICE] [-a|--all] +{} [-F DEVICE | --file=DEVICE] [-g|--save]"; +const SUMMARY: &str = "Print or change terminal characteristics."; + +pub struct Flag { + name: &'static str, + flag: T, + show: bool, + sane: bool, +} + +trait TermiosFlag { + fn is_in(&self, termios: &Termios) -> bool; + fn apply(&self, termios: &mut Termios, val: bool); +} + +mod options { + pub const ALL: &str = "all"; + pub const SAVE: &str = "save"; + pub const FILE: &str = "file"; + pub const SETTINGS: &str = "settings"; +} + +struct Options<'a> { + all: bool, + _save: bool, + file: RawFd, + settings: Option>, +} + +impl<'a> Options<'a> { + fn from(matches: &'a ArgMatches) -> io::Result { + Ok(Self { + all: matches.is_present(options::ALL), + _save: matches.is_present(options::SAVE), + file: match matches.value_of(options::FILE) { + Some(_f) => todo!(), + None => stdout().as_raw_fd(), + }, + settings: matches.values_of(options::SETTINGS).map(|v| v.collect()), + }) + } +} + +#[uucore::main] +pub fn uumain(args: impl uucore::Args) -> UResult<()> { + let args = args + .collect_str(InvalidEncodingHandling::ConvertLossy) + .accept_any(); + + let matches = uu_app().get_matches_from(args); + + let opts = Options::from(&matches)?; + + stty(&opts) +} + +fn stty(opts: &Options) -> UResult<()> { + // TODO: Figure out the right error message + let mut termios = tcgetattr(opts.file).expect("Could not get terminal attributes"); + if let Some(settings) = &opts.settings { + for setting in settings { + apply_setting(&mut termios, setting); + } + + tcsetattr(opts.file, nix::sys::termios::SetArg::TCSANOW, &termios) + .expect("Could not write terminal attributes"); + } else { + print_settings(&termios, opts); + } + Ok(()) +} + +fn print_settings(termios: &Termios, opts: &Options) { + if print_flags(termios, opts, &CONTROL_FLAGS) { + println!(); + } + if print_flags(termios, opts, &INPUT_FLAGS) { + println!(); + } + if print_flags(termios, opts, &OUTPUT_FLAGS) { + println!(); + } + if print_flags(termios, opts, &LOCAL_FLAGS) { + println!(); + } +} + +fn print_flags(termios: &Termios, opts: &Options, flags: &[Flag]) -> bool +where + Flag: TermiosFlag, +{ + let mut printed = false; + for flag in flags { + if !flag.show { + continue; + } + let val = flag.is_in(termios); + if opts.all || val != flag.sane { + if !val { + print!("-"); + } + print!("{} ", flag.name); + printed = true; + } + } + printed +} + +fn apply_setting(termios: &mut Termios, s: &str) -> Option<()> { + if let Some(()) = apply_flag(termios, &CONTROL_FLAGS, s) { + return Some(()); + } + if let Some(()) = apply_flag(termios, &INPUT_FLAGS, s) { + return Some(()); + } + if let Some(()) = apply_flag(termios, &OUTPUT_FLAGS, s) { + return Some(()); + } + if let Some(()) = apply_flag(termios, &LOCAL_FLAGS, s) { + return Some(()); + } + None +} + +fn apply_flag(termios: &mut Termios, flags: &[Flag], name: &str) -> Option<()> +where + T: Copy, + Flag: TermiosFlag, +{ + let (remove, name) = strip_hyphen(name); + find(flags, name)?.apply(termios, !remove); + Some(()) +} + +fn strip_hyphen(s: &str) -> (bool, &str) { + match s.strip_prefix('-') { + Some(s) => (true, s), + None => (false, s), + } +} + +pub fn uu_app<'a>() -> Command<'a> { + Command::new(uucore::util_name()) + .name(NAME) + .version(crate_version!()) + .override_usage(format_usage(USAGE)) + .about(SUMMARY) + .infer_long_args(true) + .arg(Arg::new(options::ALL).short('a').long(options::ALL)) + .arg(Arg::new(options::SAVE).short('g').long(options::SAVE)) + .arg( + Arg::new(options::FILE) + .short('F') + .long(options::FILE) + .takes_value(true) + .value_hint(clap::ValueHint::FilePath), + ) + .arg( + Arg::new(options::SETTINGS) + .takes_value(true) + .multiple_values(true), + ) +} + +impl TermiosFlag for Flag { + fn is_in(&self, termios: &Termios) -> bool { + termios.control_flags.contains(self.flag) + } + + fn apply(&self, termios: &mut Termios, val: bool) { + termios.control_flags.set(self.flag, val) + } +} + +impl TermiosFlag for Flag { + fn is_in(&self, termios: &Termios) -> bool { + termios.input_flags.contains(self.flag) + } + + fn apply(&self, termios: &mut Termios, val: bool) { + termios.input_flags.set(self.flag, val) + } +} + +impl TermiosFlag for Flag { + fn is_in(&self, termios: &Termios) -> bool { + termios.output_flags.contains(self.flag) + } + + fn apply(&self, termios: &mut Termios, val: bool) { + termios.output_flags.set(self.flag, val) + } +} + +impl TermiosFlag for Flag { + fn is_in(&self, termios: &Termios) -> bool { + termios.local_flags.contains(self.flag) + } + + fn apply(&self, termios: &mut Termios, val: bool) { + termios.local_flags.set(self.flag, val) + } +} + +fn find<'a, T>(flags: &'a [Flag], flag_name: &str) -> Option<&'a Flag> +where + T: Copy, +{ + flags.iter().find_map(|flag| { + if flag.name == flag_name { + Some(flag) + } else { + None + } + }) +} From a23702caebb68ce3c89a5845d3db1571ee2456b6 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sat, 25 Jun 2022 22:37:28 +0200 Subject: [PATCH 18/44] add some simple tests to stty (still failing) --- tests/by-util/test_stty.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/by-util/test_stty.rs diff --git a/tests/by-util/test_stty.rs b/tests/by-util/test_stty.rs new file mode 100644 index 000000000..544d20afe --- /dev/null +++ b/tests/by-util/test_stty.rs @@ -0,0 +1,18 @@ +use crate::common::util::*; + +#[test] +fn runs() { + new_ucmd!().succeeds(); +} + +#[test] +fn print_all() { + let res = new_ucmd!().succeeds(); + + // Random selection of flags to check for + for flag in [ + "parenb", "parmrk", "ixany", "iuclc", "onlcr", "ofdel", "icanon", "noflsh", + ] { + res.stdout_contains(flag); + } +} From 4cda8f33e70d68688045ae816b25c2f2f21e50e8 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Mon, 27 Jun 2022 13:00:31 +0200 Subject: [PATCH 19/44] stty: add grouped flags --- src/uu/stty/src/flags.rs | 391 ++++++++------------------------------- src/uu/stty/src/stty.rs | 226 +++++++++++++--------- 2 files changed, 218 insertions(+), 399 deletions(-) diff --git a/src/uu/stty/src/flags.rs b/src/uu/stty/src/flags.rs index b2688cb8d..7a985a04b 100644 --- a/src/uu/stty/src/flags.rs +++ b/src/uu/stty/src/flags.rs @@ -3,330 +3,95 @@ // * For the full copyright and license information, please view the LICENSE file // * that was distributed with this source code. -// spell-checker:ignore parenb parodd cmspar hupcl cstopb cread clocal crtscts +// spell-checker:ignore parenb parodd cmspar hupcl cstopb cread clocal crtscts CSIZE // spell-checker:ignore ignbrk brkint ignpar parmrk inpck istrip inlcr igncr icrnl ixoff ixon iuclc ixany imaxbel iutf -// spell-checker:ignore opost olcuc ocrnl onlcr onocr onlret ofill ofdel +// spell-checker:ignore opost olcuc ocrnl onlcr onocr onlret ofill ofdel nldly crdly tabdly bsdly vtdly ffdly // spell-checker:ignore isig icanon iexten echoe crterase echok echonl noflsh xcase tostop echoprt prterase echoctl ctlecho echoke crtkill flusho extproc use crate::Flag; -use nix::sys::termios::{ControlFlags, InputFlags, LocalFlags, OutputFlags}; +use nix::sys::termios::{ControlFlags as C, InputFlags as I, LocalFlags as L, OutputFlags as O}; -pub const CONTROL_FLAGS: [Flag; 8] = [ - Flag { - name: "parenb", - flag: ControlFlags::PARENB, - show: true, - sane: false, - }, - Flag { - name: "parodd", - flag: ControlFlags::PARODD, - show: true, - sane: false, - }, - Flag { - name: "cmspar", - flag: ControlFlags::CMSPAR, - show: true, - sane: false, - }, - Flag { - name: "hupcl", - flag: ControlFlags::HUPCL, - show: true, - sane: true, - }, - Flag { - name: "cstopb", - flag: ControlFlags::CSTOPB, - show: true, - sane: false, - }, - Flag { - name: "cread", - flag: ControlFlags::CREAD, - show: true, - sane: true, - }, - Flag { - name: "clocal", - flag: ControlFlags::CLOCAL, - show: true, - sane: false, - }, - Flag { - name: "crtscts", - flag: ControlFlags::CRTSCTS, - show: true, - sane: false, - }, +pub const CONTROL_FLAGS: [Flag; 12] = [ + Flag::new("parenb", C::PARENB), + Flag::new("parodd", C::PARODD), + Flag::new("cmspar", C::CMSPAR), + Flag::new("cs5", C::CS5).group(C::CSIZE), + Flag::new("cs6", C::CS6).group(C::CSIZE), + Flag::new("cs7", C::CS7).group(C::CSIZE), + Flag::new("cs8", C::CS8).group(C::CSIZE).sane(), + Flag::new("hupcl", C::HUPCL).sane(), + Flag::new("cstopb", C::CSTOPB), + Flag::new("cread", C::CREAD).sane(), + Flag::new("clocal", C::CLOCAL), + Flag::new("crtscts", C::CRTSCTS), ]; -pub const INPUT_FLAGS: [Flag; 15] = [ - Flag { - name: "ignbrk", - flag: InputFlags::IGNBRK, - show: true, - sane: false, - }, - Flag { - name: "brkint", - flag: InputFlags::BRKINT, - show: true, - sane: true, - }, - Flag { - name: "ignpar", - flag: InputFlags::IGNPAR, - show: true, - sane: false, - }, - Flag { - name: "parmrk", - flag: InputFlags::PARMRK, - show: true, - sane: false, - }, - Flag { - name: "inpck", - flag: InputFlags::INPCK, - show: true, - sane: false, - }, - Flag { - name: "istrip", - flag: InputFlags::ISTRIP, - show: true, - sane: false, - }, - Flag { - name: "inlcr", - flag: InputFlags::INLCR, - show: true, - sane: false, - }, - Flag { - name: "igncr", - flag: InputFlags::IGNCR, - show: true, - sane: false, - }, - Flag { - name: "icrnl", - flag: InputFlags::ICRNL, - show: true, - sane: true, - }, - Flag { - name: "ixoff", - flag: InputFlags::IXOFF, - show: true, - sane: false, - }, - Flag { - name: "tandem", - flag: InputFlags::IXOFF, - show: false, - sane: false, - }, - Flag { - name: "ixon", - flag: InputFlags::IXON, - show: true, - sane: false, - }, +pub const INPUT_FLAGS: [Flag; 15] = [ + Flag::new("ignbrk", I::IGNBRK), + Flag::new("brkint", I::BRKINT).sane(), + Flag::new("ignpar", I::IGNPAR), + Flag::new("parmrk", I::PARMRK), + Flag::new("inpck", I::INPCK), + Flag::new("istrip", I::ISTRIP), + Flag::new("inlcr", I::INLCR), + Flag::new("igncr", I::IGNCR), + Flag::new("icrnl", I::ICRNL).sane(), + Flag::new("ixoff", I::IXOFF), + Flag::new("tandem", I::IXOFF), + Flag::new("ixon", I::IXON), // not supported by nix - // Flag { - // name: "iuclc", - // flag: InputFlags::IUCLC, - // show: true, - // default: false, - // }, - Flag { - name: "ixany", - flag: InputFlags::IXANY, - show: true, - sane: false, - }, - Flag { - name: "imaxbel", - flag: InputFlags::IMAXBEL, - show: true, - sane: true, - }, - Flag { - name: "iutf8", - flag: InputFlags::IUTF8, - show: true, - sane: false, - }, + // Flag::new("iuclc", I::IUCLC), + Flag::new("ixany", I::IXANY).sane(), + Flag::new("imaxbel", I::IMAXBEL).sane(), + Flag::new("iutf8", I::IUTF8).sane(), ]; -pub const OUTPUT_FLAGS: [Flag; 8] = [ - Flag { - name: "opost", - flag: OutputFlags::OPOST, - show: true, - sane: true, - }, - Flag { - name: "olcuc", - flag: OutputFlags::OLCUC, - show: true, - sane: false, - }, - Flag { - name: "ocrnl", - flag: OutputFlags::OCRNL, - show: true, - sane: false, - }, - Flag { - name: "onlcr", - flag: OutputFlags::ONLCR, - show: true, - sane: true, - }, - Flag { - name: "onocr", - flag: OutputFlags::ONOCR, - show: true, - sane: false, - }, - Flag { - name: "onlret", - flag: OutputFlags::ONLRET, - show: true, - sane: false, - }, - Flag { - name: "ofill", - flag: OutputFlags::OFILL, - show: true, - sane: false, - }, - Flag { - name: "ofdel", - flag: OutputFlags::OFDEL, - show: true, - sane: false, - }, +pub const OUTPUT_FLAGS: [Flag; 24] = [ + Flag::new("opost", O::OPOST).sane(), + Flag::new("olcuc", O::OLCUC), + Flag::new("ocrnl", O::OCRNL), + Flag::new("onlcr", O::ONLCR).sane(), + Flag::new("onocr", O::ONOCR), + Flag::new("onlret", O::ONLRET), + Flag::new("ofill", O::OFILL), + Flag::new("ofdel", O::OFDEL), + Flag::new("nl0", O::NL0).group(O::NLDLY).sane(), + Flag::new("nl1", O::NL1).group(O::NLDLY), + Flag::new("cr0", O::CR0).group(O::CRDLY).sane(), + Flag::new("cr1", O::CR1).group(O::CRDLY), + Flag::new("cr2", O::CR2).group(O::CRDLY), + Flag::new("cr3", O::CR3).group(O::CRDLY), + Flag::new("tab0", O::TAB0).group(O::TABDLY).sane(), + Flag::new("tab1", O::TAB1).group(O::TABDLY), + Flag::new("tab2", O::TAB2).group(O::TABDLY), + Flag::new("tab3", O::TAB3).group(O::TABDLY), + Flag::new("bs0", O::BS0).group(O::BSDLY).sane(), + Flag::new("bs1", O::BS1).group(O::BSDLY), + Flag::new("vt0", O::VT0).group(O::VTDLY).sane(), + Flag::new("vt1", O::VT1).group(O::VTDLY), + Flag::new("ff0", O::FF0).group(O::FFDLY).sane(), + Flag::new("ff1", O::FF1).group(O::FFDLY), ]; -pub const LOCAL_FLAGS: [Flag; 18] = [ - Flag { - name: "isig", - flag: LocalFlags::ISIG, - show: true, - sane: true, - }, - Flag { - name: "icanon", - flag: LocalFlags::ICANON, - show: true, - sane: true, - }, - Flag { - name: "iexten", - flag: LocalFlags::IEXTEN, - show: true, - sane: true, - }, - Flag { - name: "echo", - flag: LocalFlags::ECHO, - show: true, - sane: true, - }, - Flag { - name: "echoe", - flag: LocalFlags::ECHOE, - show: true, - sane: true, - }, - Flag { - name: "crterase", - flag: LocalFlags::ECHOE, - show: false, - sane: true, - }, - Flag { - name: "echok", - flag: LocalFlags::ECHOK, - show: true, - sane: true, - }, - Flag { - name: "echonl", - flag: LocalFlags::ECHONL, - show: true, - sane: false, - }, - Flag { - name: "noflsh", - flag: LocalFlags::NOFLSH, - show: true, - sane: false, - }, +pub const LOCAL_FLAGS: [Flag; 18] = [ + Flag::new("isig", L::ISIG).sane(), + Flag::new("icanon", L::ICANON).sane(), + Flag::new("iexten", L::IEXTEN).sane(), + Flag::new("echo", L::ECHO).sane(), + Flag::new("echoe", L::ECHOE).sane(), + Flag::new("crterase", L::ECHOE).hidden().sane(), + Flag::new("echok", L::ECHOK).sane(), + Flag::new("echonl", L::ECHONL), + Flag::new("noflsh", L::NOFLSH), // Not supported by nix - // Flag { - // name: "xcase", - // flag: LocalFlags::XCASE, - // show: true, - // sane: false, - // }, - Flag { - name: "tostop", - flag: LocalFlags::TOSTOP, - show: true, - sane: false, - }, - Flag { - name: "echoprt", - flag: LocalFlags::ECHOPRT, - show: true, - sane: false, - }, - Flag { - name: "prterase", - flag: LocalFlags::ECHOPRT, - show: false, - sane: false, - }, - Flag { - name: "echoctl", - flag: LocalFlags::ECHOCTL, - show: true, - sane: true, - }, - Flag { - name: "ctlecho", - flag: LocalFlags::ECHOCTL, - show: false, - sane: true, - }, - Flag { - name: "echoke", - flag: LocalFlags::ECHOKE, - show: true, - sane: true, - }, - Flag { - name: "crtkill", - flag: LocalFlags::ECHOKE, - show: false, - sane: true, - }, - Flag { - name: "flusho", - flag: LocalFlags::FLUSHO, - show: true, - sane: false, - }, - Flag { - name: "extproc", - flag: LocalFlags::EXTPROC, - show: true, - sane: false, - }, + // Flag::new("xcase", L::XCASE), + Flag::new("tostop", L::TOSTOP), + Flag::new("echoprt", L::ECHOPRT), + Flag::new("prterase", L::ECHOPRT).hidden(), + Flag::new("echoctl", L::ECHOCTL).sane(), + Flag::new("ctlecho", L::ECHOCTL).sane().hidden(), + Flag::new("echoke", L::ECHOKE).sane(), + Flag::new("crtkill", L::ECHOKE).sane().hidden(), + Flag::new("flusho", L::FLUSHO), + Flag::new("extproc", L::EXTPROC), ]; diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 52cd5995b..fa29f761b 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -12,8 +12,9 @@ use nix::sys::termios::{ tcgetattr, tcsetattr, ControlFlags, InputFlags, LocalFlags, OutputFlags, Termios, }; use std::io::{self, stdout}; +use std::ops::ControlFlow; use std::os::unix::io::{AsRawFd, RawFd}; -use uucore::error::UResult; +use uucore::error::{UResult, USimpleError}; use uucore::{format_usage, InvalidEncodingHandling}; use flags::{CONTROL_FLAGS, INPUT_FLAGS, LOCAL_FLAGS, OUTPUT_FLAGS}; @@ -25,15 +26,53 @@ const USAGE: &str = "\ {} [-F DEVICE | --file=DEVICE] [-g|--save]"; const SUMMARY: &str = "Print or change terminal characteristics."; +#[derive(Clone, Copy, Debug)] pub struct Flag { name: &'static str, flag: T, show: bool, sane: bool, + group: Option, } -trait TermiosFlag { - fn is_in(&self, termios: &Termios) -> bool; +impl Flag +where + T: Copy, +{ + pub const fn new(name: &'static str, flag: T) -> Self { + Flag { + name, + flag, + show: true, + sane: false, + group: None, + } + } + + pub const fn hidden(&self) -> Self { + Self { + show: false, + ..*self + } + } + + pub const fn sane(&self) -> Self { + Self { + sane: true, + ..*self + } + } + + pub const fn group(&self, group: T) -> Self { + Self { + group: Some(group), + ..*self + } + } +} + +trait TermiosFlag: Copy { + fn is_in(&self, termios: &Termios, group: Option) -> bool; fn apply(&self, termios: &mut Termios, val: bool); } @@ -83,7 +122,12 @@ fn stty(opts: &Options) -> UResult<()> { let mut termios = tcgetattr(opts.file).expect("Could not get terminal attributes"); if let Some(settings) = &opts.settings { for setting in settings { - apply_setting(&mut termios, setting); + if let ControlFlow::Break(false) = apply_setting(&mut termios, setting) { + return Err(USimpleError::new( + 1, + format!("invalid argument '{}'", setting), + )); + } } tcsetattr(opts.file, nix::sys::termios::SetArg::TCSANOW, &termios) @@ -95,72 +139,91 @@ fn stty(opts: &Options) -> UResult<()> { } fn print_settings(termios: &Termios, opts: &Options) { - if print_flags(termios, opts, &CONTROL_FLAGS) { - println!(); - } - if print_flags(termios, opts, &INPUT_FLAGS) { - println!(); - } - if print_flags(termios, opts, &OUTPUT_FLAGS) { - println!(); - } - if print_flags(termios, opts, &LOCAL_FLAGS) { - println!(); - } + print_flags(termios, opts, &CONTROL_FLAGS); + print_flags(termios, opts, &INPUT_FLAGS); + print_flags(termios, opts, &OUTPUT_FLAGS); + print_flags(termios, opts, &LOCAL_FLAGS); } -fn print_flags(termios: &Termios, opts: &Options, flags: &[Flag]) -> bool -where - Flag: TermiosFlag, -{ +fn print_flags(termios: &Termios, opts: &Options, flags: &[Flag]) { let mut printed = false; - for flag in flags { - if !flag.show { + for &Flag { + name, + flag, + show, + sane, + group, + } in flags + { + if !show { continue; } - let val = flag.is_in(termios); - if opts.all || val != flag.sane { - if !val { - print!("-"); + let val = flag.is_in(termios, group); + if group.is_some() { + if val && (!sane || opts.all) { + print!("{name} "); + printed = true; + } + } else { + if opts.all || val != sane { + if !val { + print!("-"); + } + print!("{name} "); + printed = true; } - print!("{} ", flag.name); - printed = true; } } - printed + if printed { + println!(); + } } -fn apply_setting(termios: &mut Termios, s: &str) -> Option<()> { - if let Some(()) = apply_flag(termios, &CONTROL_FLAGS, s) { - return Some(()); - } - if let Some(()) = apply_flag(termios, &INPUT_FLAGS, s) { - return Some(()); - } - if let Some(()) = apply_flag(termios, &OUTPUT_FLAGS, s) { - return Some(()); - } - if let Some(()) = apply_flag(termios, &LOCAL_FLAGS, s) { - return Some(()); - } - None -} - -fn apply_flag(termios: &mut Termios, flags: &[Flag], name: &str) -> Option<()> -where - T: Copy, - Flag: TermiosFlag, -{ - let (remove, name) = strip_hyphen(name); - find(flags, name)?.apply(termios, !remove); - Some(()) -} - -fn strip_hyphen(s: &str) -> (bool, &str) { - match s.strip_prefix('-') { +/// Apply a single setting +/// +/// The value inside the `Break` variant of the `ControlFlow` indicates whether +/// the setting has been applied. +fn apply_setting(termios: &mut Termios, s: &str) -> ControlFlow { + let (remove, name) = match s.strip_prefix('-') { Some(s) => (true, s), None => (false, s), + }; + apply_flag(termios, &CONTROL_FLAGS, name, remove)?; + apply_flag(termios, &INPUT_FLAGS, name, remove)?; + apply_flag(termios, &OUTPUT_FLAGS, name, remove)?; + apply_flag(termios, &LOCAL_FLAGS, name, remove)?; + ControlFlow::Break(false) +} + +/// Apply a flag to a slice of flags +/// +/// The value inside the `Break` variant of the `ControlFlow` indicates whether +/// the setting has been applied. +fn apply_flag( + termios: &mut Termios, + flags: &[Flag], + input: &str, + remove: bool, +) -> ControlFlow { + for Flag { + name, flag, group, .. + } in flags + { + if input == *name { + // Flags with groups cannot be removed + // Since the name matches, we can short circuit and don't have to check the other flags. + if remove || group.is_some() { + return ControlFlow::Break(false); + } + // If there is a group, the bits for that group should be cleared before applying the flag + if let Some(group) = group { + group.apply(termios, false); + } + flag.apply(termios, !remove); + return ControlFlow::Break(true); + } } + ControlFlow::Continue(()) } pub fn uu_app<'a>() -> Command<'a> { @@ -186,55 +249,46 @@ pub fn uu_app<'a>() -> Command<'a> { ) } -impl TermiosFlag for Flag { - fn is_in(&self, termios: &Termios) -> bool { - termios.control_flags.contains(self.flag) +impl TermiosFlag for ControlFlags { + fn is_in(&self, termios: &Termios, group: Option) -> bool { + termios.control_flags.contains(*self) + && group.map_or(true, |g| !termios.control_flags.intersects(g - *self)) } fn apply(&self, termios: &mut Termios, val: bool) { - termios.control_flags.set(self.flag, val) + termios.control_flags.set(*self, val) } } -impl TermiosFlag for Flag { - fn is_in(&self, termios: &Termios) -> bool { - termios.input_flags.contains(self.flag) +impl TermiosFlag for InputFlags { + fn is_in(&self, termios: &Termios, group: Option) -> bool { + termios.input_flags.contains(*self) + && group.map_or(true, |g| !termios.input_flags.intersects(g - *self)) } fn apply(&self, termios: &mut Termios, val: bool) { - termios.input_flags.set(self.flag, val) + termios.input_flags.set(*self, val) } } -impl TermiosFlag for Flag { - fn is_in(&self, termios: &Termios) -> bool { - termios.output_flags.contains(self.flag) +impl TermiosFlag for OutputFlags { + fn is_in(&self, termios: &Termios, group: Option) -> bool { + termios.output_flags.contains(*self) + && group.map_or(true, |g| !termios.output_flags.intersects(g - *self)) } fn apply(&self, termios: &mut Termios, val: bool) { - termios.output_flags.set(self.flag, val) + termios.output_flags.set(*self, val) } } -impl TermiosFlag for Flag { - fn is_in(&self, termios: &Termios) -> bool { - termios.local_flags.contains(self.flag) +impl TermiosFlag for LocalFlags { + fn is_in(&self, termios: &Termios, group: Option) -> bool { + termios.local_flags.contains(*self) + && group.map_or(true, |g| !termios.local_flags.intersects(g - *self)) } fn apply(&self, termios: &mut Termios, val: bool) { - termios.local_flags.set(self.flag, val) + termios.local_flags.set(*self, val) } } - -fn find<'a, T>(flags: &'a [Flag], flag_name: &str) -> Option<&'a Flag> -where - T: Copy, -{ - flags.iter().find_map(|flag| { - if flag.name == flag_name { - Some(flag) - } else { - None - } - }) -} From 6896a85b412a06bd68545585f1bf868243d6c81d Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Mon, 27 Jun 2022 13:03:48 +0200 Subject: [PATCH 20/44] test_stty: fix spell checker errors --- tests/by-util/test_stty.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/by-util/test_stty.rs b/tests/by-util/test_stty.rs index 544d20afe..7dc0b20d2 100644 --- a/tests/by-util/test_stty.rs +++ b/tests/by-util/test_stty.rs @@ -1,3 +1,5 @@ +// spell-checker:ignore parenb parmrk ixany iuclc onlcr ofdel icanon noflsh + use crate::common::util::*; #[test] From 0c44fc07d26c013e7bfc38f5f92bc1b446abb064 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Mon, 27 Jun 2022 13:04:56 +0200 Subject: [PATCH 21/44] stty: fix ixany and iutf8 not sane --- src/uu/stty/src/flags.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/stty/src/flags.rs b/src/uu/stty/src/flags.rs index 7a985a04b..226c5ce66 100644 --- a/src/uu/stty/src/flags.rs +++ b/src/uu/stty/src/flags.rs @@ -41,9 +41,9 @@ pub const INPUT_FLAGS: [Flag; 15] = [ Flag::new("ixon", I::IXON), // not supported by nix // Flag::new("iuclc", I::IUCLC), - Flag::new("ixany", I::IXANY).sane(), + Flag::new("ixany", I::IXANY), Flag::new("imaxbel", I::IMAXBEL).sane(), - Flag::new("iutf8", I::IUTF8).sane(), + Flag::new("iutf8", I::IUTF8), ]; pub const OUTPUT_FLAGS: [Flag; 24] = [ From 96ea77201631913665a52e590a9b35813fc55565 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Mon, 27 Jun 2022 13:07:35 +0200 Subject: [PATCH 22/44] stty: fix clippy warnings --- src/uu/stty/src/stty.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index fa29f761b..fefbf2014 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -40,7 +40,7 @@ where T: Copy, { pub const fn new(name: &'static str, flag: T) -> Self { - Flag { + Self { name, flag, show: true, @@ -164,14 +164,12 @@ fn print_flags(termios: &Termios, opts: &Options, flags: &[Flag< print!("{name} "); printed = true; } - } else { - if opts.all || val != sane { - if !val { - print!("-"); - } - print!("{name} "); - printed = true; + } else if opts.all || val != sane { + if !val { + print!("-"); } + print!("{name} "); + printed = true; } } if printed { @@ -256,7 +254,7 @@ impl TermiosFlag for ControlFlags { } fn apply(&self, termios: &mut Termios, val: bool) { - termios.control_flags.set(*self, val) + termios.control_flags.set(*self, val); } } @@ -267,7 +265,7 @@ impl TermiosFlag for InputFlags { } fn apply(&self, termios: &mut Termios, val: bool) { - termios.input_flags.set(*self, val) + termios.input_flags.set(*self, val); } } @@ -278,7 +276,7 @@ impl TermiosFlag for OutputFlags { } fn apply(&self, termios: &mut Termios, val: bool) { - termios.output_flags.set(*self, val) + termios.output_flags.set(*self, val); } } @@ -289,6 +287,6 @@ impl TermiosFlag for LocalFlags { } fn apply(&self, termios: &mut Termios, val: bool) { - termios.local_flags.set(*self, val) + termios.local_flags.set(*self, val); } } From eac88022b2dc2ffc5624a576598e77d526a29a1f Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Mon, 27 Jun 2022 13:45:59 +0200 Subject: [PATCH 23/44] stty: fix setting grouped flags --- src/uu/stty/src/stty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index fefbf2014..1eecf5654 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -210,7 +210,7 @@ fn apply_flag( if input == *name { // Flags with groups cannot be removed // Since the name matches, we can short circuit and don't have to check the other flags. - if remove || group.is_some() { + if remove && group.is_some() { return ControlFlow::Break(false); } // If there is a group, the bits for that group should be cleared before applying the flag From 679fd2371e1105c8da8d2e6012e56fcc521871be Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Mon, 27 Jun 2022 13:46:34 +0200 Subject: [PATCH 24/44] stty: disallow combining settings with --all and --save --- src/uu/stty/src/stty.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 1eecf5654..76a281462 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -85,7 +85,7 @@ mod options { struct Options<'a> { all: bool, - _save: bool, + save: bool, file: RawFd, settings: Option>, } @@ -94,7 +94,7 @@ impl<'a> Options<'a> { fn from(matches: &'a ArgMatches) -> io::Result { Ok(Self { all: matches.is_present(options::ALL), - _save: matches.is_present(options::SAVE), + save: matches.is_present(options::SAVE), file: match matches.value_of(options::FILE) { Some(_f) => todo!(), None => stdout().as_raw_fd(), @@ -120,7 +120,15 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { fn stty(opts: &Options) -> UResult<()> { // TODO: Figure out the right error message let mut termios = tcgetattr(opts.file).expect("Could not get terminal attributes"); + if let Some(settings) = &opts.settings { + if opts.save || opts.all { + return Err(USimpleError::new( + 1, + "when specifying an output style, modes may not be set", + )); + } + for setting in settings { if let ControlFlow::Break(false) = apply_setting(&mut termios, setting) { return Err(USimpleError::new( From cc147a7c8dc6420150a035d5079af46e94ffdb07 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Mon, 27 Jun 2022 19:45:38 +0200 Subject: [PATCH 25/44] stty: expand --help information --- src/uu/stty/src/stty.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 76a281462..68c128a7b 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -21,9 +21,9 @@ use flags::{CONTROL_FLAGS, INPUT_FLAGS, LOCAL_FLAGS, OUTPUT_FLAGS}; const NAME: &str = "stty"; const USAGE: &str = "\ -{} [-F DEVICE | --file=DEVICE] [SETTING]... -{} [-F DEVICE | --file=DEVICE] [-a|--all] -{} [-F DEVICE | --file=DEVICE] [-g|--save]"; + {} [-F DEVICE | --file=DEVICE] [SETTING]... + {} [-F DEVICE | --file=DEVICE] [-a|--all] + {} [-F DEVICE | --file=DEVICE] [-g|--save]"; const SUMMARY: &str = "Print or change terminal characteristics."; #[derive(Clone, Copy, Debug)] @@ -239,19 +239,32 @@ pub fn uu_app<'a>() -> Command<'a> { .override_usage(format_usage(USAGE)) .about(SUMMARY) .infer_long_args(true) - .arg(Arg::new(options::ALL).short('a').long(options::ALL)) - .arg(Arg::new(options::SAVE).short('g').long(options::SAVE)) + .arg( + Arg::new(options::ALL) + .short('a') + .long(options::ALL) + .help("print all current settings in human-readable form"), + ) + .arg( + Arg::new(options::SAVE) + .short('g') + .long(options::SAVE) + .help("print all current settings in a stty-readable form"), + ) .arg( Arg::new(options::FILE) .short('F') .long(options::FILE) .takes_value(true) - .value_hint(clap::ValueHint::FilePath), + .value_hint(clap::ValueHint::FilePath) + .value_name("DEVICE") + .help("open and use the specified DEVICE instead of stdin") ) .arg( Arg::new(options::SETTINGS) .takes_value(true) - .multiple_values(true), + .multiple_values(true) + .help("settings to change"), ) } From f861fc0854934a660fb0abac7e08d8cba82eaaf3 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 1 Jul 2022 15:55:58 +0200 Subject: [PATCH 26/44] stty: print special terminal information --- src/uu/stty/src/flags.rs | 106 ++++++++++++++++++++++++++++++++++++- src/uu/stty/src/stty.rs | 91 +++++++++++++++++++++++++------ tests/by-util/test_stty.rs | 35 ++++++++++++ 3 files changed, 214 insertions(+), 18 deletions(-) diff --git a/src/uu/stty/src/flags.rs b/src/uu/stty/src/flags.rs index 226c5ce66..14042ff70 100644 --- a/src/uu/stty/src/flags.rs +++ b/src/uu/stty/src/flags.rs @@ -9,7 +9,9 @@ // spell-checker:ignore isig icanon iexten echoe crterase echok echonl noflsh xcase tostop echoprt prterase echoctl ctlecho echoke crtkill flusho extproc use crate::Flag; -use nix::sys::termios::{ControlFlags as C, InputFlags as I, LocalFlags as L, OutputFlags as O}; +use nix::sys::termios::{ + BaudRate, ControlFlags as C, InputFlags as I, LocalFlags as L, OutputFlags as O, +}; pub const CONTROL_FLAGS: [Flag; 12] = [ Flag::new("parenb", C::PARENB), @@ -19,7 +21,7 @@ pub const CONTROL_FLAGS: [Flag; 12] = [ Flag::new("cs6", C::CS6).group(C::CSIZE), Flag::new("cs7", C::CS7).group(C::CSIZE), Flag::new("cs8", C::CS8).group(C::CSIZE).sane(), - Flag::new("hupcl", C::HUPCL).sane(), + Flag::new("hupcl", C::HUPCL), Flag::new("cstopb", C::CSTOPB), Flag::new("cread", C::CREAD).sane(), Flag::new("clocal", C::CLOCAL), @@ -95,3 +97,103 @@ pub const LOCAL_FLAGS: [Flag; 18] = [ Flag::new("flusho", L::FLUSHO), Flag::new("extproc", L::EXTPROC), ]; + +pub const BAUD_RATES: &[(&str, BaudRate)] = &[ + ("0", BaudRate::B0), + ("50", BaudRate::B50), + ("75", BaudRate::B75), + ("110", BaudRate::B110), + ("134", BaudRate::B134), + ("150", BaudRate::B150), + ("200", BaudRate::B200), + ("300", BaudRate::B300), + ("600", BaudRate::B600), + ("1200", BaudRate::B1200), + ("1800", BaudRate::B1800), + ("2400", BaudRate::B2400), + #[cfg(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd" + ))] + ("4800", BaudRate::B4800), + ("9600", BaudRate::B9600), + #[cfg(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd" + ))] + ("14400", BaudRate::B14400), + ("19200", BaudRate::B19200), + #[cfg(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd" + ))] + ("28800", BaudRate::B28800), + ("38400", BaudRate::B38400), + ("57600", BaudRate::B57600), + #[cfg(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd" + ))] + ("76800", BaudRate::B76800), + ("115200", BaudRate::B115200), + ("230400", BaudRate::B230400), + #[cfg(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd" + ))] + ("460800", BaudRate::B460800), + #[cfg(any(target_os = "android", target_os = "linux"))] + ("500000", BaudRate::B500000), + #[cfg(any(target_os = "android", target_os = "linux"))] + ("576000", BaudRate::B576000), + #[cfg(any( + target_os = "android", + target_os = "freebsd", + target_os = "linux", + target_os = "netbsd" + ))] + ("921600", BaudRate::B921600), + #[cfg(any(target_os = "android", target_os = "linux"))] + ("1000000", BaudRate::B1000000), + #[cfg(any(target_os = "android", target_os = "linux"))] + ("1152000", BaudRate::B1152000), + #[cfg(any(target_os = "android", target_os = "linux"))] + ("1500000", BaudRate::B1500000), + #[cfg(any(target_os = "android", target_os = "linux"))] + ("2000000", BaudRate::B2000000), + #[cfg(any( + target_os = "android", + all(target_os = "linux", not(target_arch = "sparc64")) + ))] + ("2500000", BaudRate::B2500000), + #[cfg(any( + target_os = "android", + all(target_os = "linux", not(target_arch = "sparc64")) + ))] + ("3000000", BaudRate::B3000000), + #[cfg(any( + target_os = "android", + all(target_os = "linux", not(target_arch = "sparc64")) + ))] + ("3500000", BaudRate::B3500000), + #[cfg(any( + target_os = "android", + all(target_os = "linux", not(target_arch = "sparc64")) + ))] + ("4000000", BaudRate::B4000000), +]; diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 68c128a7b..5cabe6da6 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -3,21 +3,23 @@ // * For the full copyright and license information, please view the LICENSE file // * that was distributed with this source code. -// spell-checker:ignore tcgetattr tcsetattr tcsanow +// spell-checker:ignore tcgetattr tcsetattr tcsanow tiocgwinsz tiocswinsz cfgetospeed ushort mod flags; use clap::{crate_version, Arg, ArgMatches, Command}; +use nix::libc::{c_ushort, TIOCGWINSZ, TIOCSWINSZ}; use nix::sys::termios::{ - tcgetattr, tcsetattr, ControlFlags, InputFlags, LocalFlags, OutputFlags, Termios, + cfgetospeed, tcgetattr, tcsetattr, ControlFlags, InputFlags, LocalFlags, OutputFlags, Termios, }; +use nix::{ioctl_read_bad, ioctl_write_ptr_bad}; use std::io::{self, stdout}; use std::ops::ControlFlow; use std::os::unix::io::{AsRawFd, RawFd}; use uucore::error::{UResult, USimpleError}; use uucore::{format_usage, InvalidEncodingHandling}; -use flags::{CONTROL_FLAGS, INPUT_FLAGS, LOCAL_FLAGS, OUTPUT_FLAGS}; +use flags::{BAUD_RATES, CONTROL_FLAGS, INPUT_FLAGS, LOCAL_FLAGS, OUTPUT_FLAGS}; const NAME: &str = "stty"; const USAGE: &str = "\ @@ -104,6 +106,30 @@ impl<'a> Options<'a> { } } +// Needs to be repr(C) because we pass it to the ioctl calls. +#[repr(C)] +#[derive(Default, Debug)] +pub struct TermSize { + rows: c_ushort, + columns: c_ushort, + x: c_ushort, + y: c_ushort, +} + +ioctl_read_bad!( + /// Get terminal window size + tiocgwinsz, + TIOCGWINSZ, + TermSize +); + +ioctl_write_ptr_bad!( + /// Set terminal window size + tiocswinsz, + TIOCSWINSZ, + TermSize +); + #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args @@ -118,17 +144,24 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } fn stty(opts: &Options) -> UResult<()> { - // TODO: Figure out the right error message + if opts.save && opts.all { + return Err(USimpleError::new( + 1, + "the options for verbose and stty-readable output styles are mutually exclusive", + )); + } + + if opts.settings.is_some() && (opts.save || opts.all) { + return Err(USimpleError::new( + 1, + "when specifying an output style, modes may not be set", + )); + } + + // TODO: Figure out the right error message for when tcgetattr fails let mut termios = tcgetattr(opts.file).expect("Could not get terminal attributes"); if let Some(settings) = &opts.settings { - if opts.save || opts.all { - return Err(USimpleError::new( - 1, - "when specifying an output style, modes may not be set", - )); - } - for setting in settings { if let ControlFlow::Break(false) = apply_setting(&mut termios, setting) { return Err(USimpleError::new( @@ -141,16 +174,42 @@ fn stty(opts: &Options) -> UResult<()> { tcsetattr(opts.file, nix::sys::termios::SetArg::TCSANOW, &termios) .expect("Could not write terminal attributes"); } else { - print_settings(&termios, opts); + print_settings(&termios, opts).expect("TODO: make proper error here from nix error"); } Ok(()) } -fn print_settings(termios: &Termios, opts: &Options) { +fn print_terminal_size(termios: &Termios, opts: &Options) -> nix::Result<()> { + let speed = cfgetospeed(termios); + for (text, baud_rate) in BAUD_RATES { + if *baud_rate == speed { + print!("speed {} baud; ", text); + break; + } + } + + if opts.all { + let mut size = TermSize::default(); + unsafe { tiocgwinsz(opts.file, &mut size as *mut _)? }; + print!("rows {}; columns {}; ", size.rows, size.columns); + } + + // For some reason the normal nix Termios struct does not expose the line, + // so we get the underlying libc::termios struct to get that information. + let libc_termios: nix::libc::termios = termios.clone().into(); + let line = libc_termios.c_line; + print!("line = {};", line); + println!(); + Ok(()) +} + +fn print_settings(termios: &Termios, opts: &Options) -> nix::Result<()> { + print_terminal_size(termios, opts)?; print_flags(termios, opts, &CONTROL_FLAGS); print_flags(termios, opts, &INPUT_FLAGS); print_flags(termios, opts, &OUTPUT_FLAGS); print_flags(termios, opts, &LOCAL_FLAGS); + Ok(()) } fn print_flags(termios: &Termios, opts: &Options, flags: &[Flag]) { @@ -169,14 +228,14 @@ fn print_flags(termios: &Termios, opts: &Options, flags: &[Flag< let val = flag.is_in(termios, group); if group.is_some() { if val && (!sane || opts.all) { - print!("{name} "); + print!("{} ", name); printed = true; } } else if opts.all || val != sane { if !val { print!("-"); } - print!("{name} "); + print!("{} ", name); printed = true; } } @@ -258,7 +317,7 @@ pub fn uu_app<'a>() -> Command<'a> { .takes_value(true) .value_hint(clap::ValueHint::FilePath) .value_name("DEVICE") - .help("open and use the specified DEVICE instead of stdin") + .help("open and use the specified DEVICE instead of stdin"), ) .arg( Arg::new(options::SETTINGS) diff --git a/tests/by-util/test_stty.rs b/tests/by-util/test_stty.rs index 7dc0b20d2..730ccdf37 100644 --- a/tests/by-util/test_stty.rs +++ b/tests/by-util/test_stty.rs @@ -3,11 +3,13 @@ use crate::common::util::*; #[test] +#[ignore = "Fails because cargo test does not run in a tty"] fn runs() { new_ucmd!().succeeds(); } #[test] +#[ignore = "Fails because cargo test does not run in a tty"] fn print_all() { let res = new_ucmd!().succeeds(); @@ -18,3 +20,36 @@ fn print_all() { res.stdout_contains(flag); } } + +#[test] +fn save_and_setting() { + new_ucmd!() + .args(&["--save", "nl0"]) + .fails() + .stderr_contains("when specifying an output style, modes may not be set"); +} + +#[test] +fn all_and_setting() { + new_ucmd!() + .args(&["--all", "nl0"]) + .fails() + .stderr_contains("when specifying an output style, modes may not be set"); +} + +#[test] +fn save_and_all() { + new_ucmd!() + .args(&["--save", "--all"]) + .fails() + .stderr_contains( + "the options for verbose and stty-readable output styles are mutually exclusive", + ); + + new_ucmd!() + .args(&["--all", "--save"]) + .fails() + .stderr_contains( + "the options for verbose and stty-readable output styles are mutually exclusive", + ); +} From 420c69aa9826861191b68d2b6c3c0bbfc90710bf Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sat, 2 Jul 2022 20:00:46 +0200 Subject: [PATCH 27/44] stty: make compatible with Rust pre 1.61 --- src/uu/stty/src/flags.rs | 40 ++++++++++++++++++++-------------------- src/uu/stty/src/stty.rs | 36 ++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/src/uu/stty/src/flags.rs b/src/uu/stty/src/flags.rs index 14042ff70..e564011b5 100644 --- a/src/uu/stty/src/flags.rs +++ b/src/uu/stty/src/flags.rs @@ -17,10 +17,10 @@ pub const CONTROL_FLAGS: [Flag; 12] = [ Flag::new("parenb", C::PARENB), Flag::new("parodd", C::PARODD), Flag::new("cmspar", C::CMSPAR), - Flag::new("cs5", C::CS5).group(C::CSIZE), - Flag::new("cs6", C::CS6).group(C::CSIZE), - Flag::new("cs7", C::CS7).group(C::CSIZE), - Flag::new("cs8", C::CS8).group(C::CSIZE).sane(), + Flag::new_grouped("cs5", C::CS5, C::CSIZE), + Flag::new_grouped("cs6", C::CS6, C::CSIZE), + Flag::new_grouped("cs7", C::CS7, C::CSIZE), + Flag::new_grouped("cs8", C::CS8, C::CSIZE).sane(), Flag::new("hupcl", C::HUPCL), Flag::new("cstopb", C::CSTOPB), Flag::new("cread", C::CREAD).sane(), @@ -57,22 +57,22 @@ pub const OUTPUT_FLAGS: [Flag; 24] = [ Flag::new("onlret", O::ONLRET), Flag::new("ofill", O::OFILL), Flag::new("ofdel", O::OFDEL), - Flag::new("nl0", O::NL0).group(O::NLDLY).sane(), - Flag::new("nl1", O::NL1).group(O::NLDLY), - Flag::new("cr0", O::CR0).group(O::CRDLY).sane(), - Flag::new("cr1", O::CR1).group(O::CRDLY), - Flag::new("cr2", O::CR2).group(O::CRDLY), - Flag::new("cr3", O::CR3).group(O::CRDLY), - Flag::new("tab0", O::TAB0).group(O::TABDLY).sane(), - Flag::new("tab1", O::TAB1).group(O::TABDLY), - Flag::new("tab2", O::TAB2).group(O::TABDLY), - Flag::new("tab3", O::TAB3).group(O::TABDLY), - Flag::new("bs0", O::BS0).group(O::BSDLY).sane(), - Flag::new("bs1", O::BS1).group(O::BSDLY), - Flag::new("vt0", O::VT0).group(O::VTDLY).sane(), - Flag::new("vt1", O::VT1).group(O::VTDLY), - Flag::new("ff0", O::FF0).group(O::FFDLY).sane(), - Flag::new("ff1", O::FF1).group(O::FFDLY), + Flag::new_grouped("nl0", O::NL0, O::NLDLY).sane(), + Flag::new_grouped("nl1", O::NL1, O::NLDLY), + Flag::new_grouped("cr0", O::CR0, O::CRDLY).sane(), + Flag::new_grouped("cr1", O::CR1, O::CRDLY), + Flag::new_grouped("cr2", O::CR2, O::CRDLY), + Flag::new_grouped("cr3", O::CR3, O::CRDLY), + Flag::new_grouped("tab0", O::TAB0, O::TABDLY).sane(), + Flag::new_grouped("tab1", O::TAB1, O::TABDLY), + Flag::new_grouped("tab2", O::TAB2, O::TABDLY), + Flag::new_grouped("tab3", O::TAB3, O::TABDLY), + Flag::new_grouped("bs0", O::BS0, O::BSDLY).sane(), + Flag::new_grouped("bs1", O::BS1, O::BSDLY), + Flag::new_grouped("vt0", O::VT0, O::VTDLY).sane(), + Flag::new_grouped("vt1", O::VT1, O::VTDLY), + Flag::new_grouped("ff0", O::FF0, O::FFDLY).sane(), + Flag::new_grouped("ff1", O::FF1, O::FFDLY), ]; pub const LOCAL_FLAGS: [Flag; 18] = [ diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 5cabe6da6..c53c01557 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -37,10 +37,7 @@ pub struct Flag { group: Option, } -impl Flag -where - T: Copy, -{ +impl Flag { pub const fn new(name: &'static str, flag: T) -> Self { Self { name, @@ -51,26 +48,25 @@ where } } - pub const fn hidden(&self) -> Self { - Self { - show: false, - ..*self - } - } - - pub const fn sane(&self) -> Self { - Self { - sane: true, - ..*self - } - } - - pub const fn group(&self, group: T) -> Self { + pub const fn new_grouped(name: &'static str, flag: T, group: T) -> Self { Self { + name, + flag, + show: true, + sane: false, group: Some(group), - ..*self } } + + pub const fn hidden(mut self) -> Self { + self.show = false; + self + } + + pub const fn sane(mut self) -> Self { + self.sane = true; + self + } } trait TermiosFlag: Copy { From 85e6f8659ffe81d9bbcc7f3e021e932f63b31a59 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Tue, 16 Aug 2022 11:16:33 +0200 Subject: [PATCH 28/44] stty: fix bsd/mac builds --- Cargo.lock | 2 +- src/uu/stty/src/flags.rs | 88 ++++++++++++++++------------------------ src/uu/stty/src/stty.rs | 63 +++++++++++++++++++++------- 3 files changed, 85 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c37e0ce6..e5d317659 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2913,7 +2913,7 @@ dependencies = [ name = "uu_stty" version = "0.0.14" dependencies = [ - "clap 3.1.18", + "clap 3.2.15", "nix", "uucore", ] diff --git a/src/uu/stty/src/flags.rs b/src/uu/stty/src/flags.rs index e564011b5..ad24fef30 100644 --- a/src/uu/stty/src/flags.rs +++ b/src/uu/stty/src/flags.rs @@ -9,13 +9,25 @@ // spell-checker:ignore isig icanon iexten echoe crterase echok echonl noflsh xcase tostop echoprt prterase echoctl ctlecho echoke crtkill flusho extproc use crate::Flag; -use nix::sys::termios::{ - BaudRate, ControlFlags as C, InputFlags as I, LocalFlags as L, OutputFlags as O, -}; -pub const CONTROL_FLAGS: [Flag; 12] = [ +#[cfg(not(any( + target_os = "freebsd", + target_os = "dragonfly", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd" +)))] +use nix::sys::termios::BaudRate; +use nix::sys::termios::{ControlFlags as C, InputFlags as I, LocalFlags as L, OutputFlags as O}; + +pub const CONTROL_FLAGS: &[Flag] = &[ Flag::new("parenb", C::PARENB), Flag::new("parodd", C::PARODD), + #[cfg(any( + target_os = "android", + all(target_os = "linux", not(target_arch = "mips")) + ))] Flag::new("cmspar", C::CMSPAR), Flag::new_grouped("cs5", C::CS5, C::CSIZE), Flag::new_grouped("cs6", C::CS6, C::CSIZE), @@ -28,7 +40,7 @@ pub const CONTROL_FLAGS: [Flag; 12] = [ Flag::new("crtscts", C::CRTSCTS), ]; -pub const INPUT_FLAGS: [Flag; 15] = [ +pub const INPUT_FLAGS: &[Flag] = &[ Flag::new("ignbrk", I::IGNBRK), Flag::new("brkint", I::BRKINT).sane(), Flag::new("ignpar", I::IGNPAR), @@ -48,8 +60,14 @@ pub const INPUT_FLAGS: [Flag; 15] = [ Flag::new("iutf8", I::IUTF8), ]; -pub const OUTPUT_FLAGS: [Flag; 24] = [ +pub const OUTPUT_FLAGS: &[Flag] = &[ Flag::new("opost", O::OPOST).sane(), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "linux", + target_os = "openbsd" + ))] Flag::new("olcuc", O::OLCUC), Flag::new("ocrnl", O::OCRNL), Flag::new("onlcr", O::ONLCR).sane(), @@ -75,7 +93,7 @@ pub const OUTPUT_FLAGS: [Flag; 24] = [ Flag::new_grouped("ff1", O::FF1, O::FFDLY), ]; -pub const LOCAL_FLAGS: [Flag; 18] = [ +pub const LOCAL_FLAGS: &[Flag] = &[ Flag::new("isig", L::ISIG).sane(), Flag::new("icanon", L::ICANON).sane(), Flag::new("iexten", L::IEXTEN).sane(), @@ -98,6 +116,15 @@ pub const LOCAL_FLAGS: [Flag; 18] = [ Flag::new("extproc", L::EXTPROC), ]; +// BSD's use u32 as baud rate, to using the enum is unnecessary. +#[cfg(not(any( + target_os = "freebsd", + target_os = "dragonfly", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd" +)))] pub const BAUD_RATES: &[(&str, BaudRate)] = &[ ("0", BaudRate::B0), ("50", BaudRate::B50), @@ -111,62 +138,17 @@ pub const BAUD_RATES: &[(&str, BaudRate)] = &[ ("1200", BaudRate::B1200), ("1800", BaudRate::B1800), ("2400", BaudRate::B2400), - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd" - ))] - ("4800", BaudRate::B4800), ("9600", BaudRate::B9600), - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd" - ))] - ("14400", BaudRate::B14400), ("19200", BaudRate::B19200), - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd" - ))] - ("28800", BaudRate::B28800), ("38400", BaudRate::B38400), ("57600", BaudRate::B57600), - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd" - ))] - ("76800", BaudRate::B76800), ("115200", BaudRate::B115200), ("230400", BaudRate::B230400), - #[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd" - ))] - ("460800", BaudRate::B460800), #[cfg(any(target_os = "android", target_os = "linux"))] ("500000", BaudRate::B500000), #[cfg(any(target_os = "android", target_os = "linux"))] ("576000", BaudRate::B576000), - #[cfg(any( - target_os = "android", - target_os = "freebsd", - target_os = "linux", - target_os = "netbsd" - ))] + #[cfg(any(target_os = "android", target_os = "linux",))] ("921600", BaudRate::B921600), #[cfg(any(target_os = "android", target_os = "linux"))] ("1000000", BaudRate::B1000000), diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index c53c01557..0f5476279 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -19,7 +19,16 @@ use std::os::unix::io::{AsRawFd, RawFd}; use uucore::error::{UResult, USimpleError}; use uucore::{format_usage, InvalidEncodingHandling}; -use flags::{BAUD_RATES, CONTROL_FLAGS, INPUT_FLAGS, LOCAL_FLAGS, OUTPUT_FLAGS}; +#[cfg(not(any( + target_os = "freebsd", + target_os = "dragonfly", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd" +)))] +use flags::BAUD_RATES; +use flags::{CONTROL_FLAGS, INPUT_FLAGS, LOCAL_FLAGS, OUTPUT_FLAGS}; const NAME: &str = "stty"; const USAGE: &str = "\ @@ -177,6 +186,28 @@ fn stty(opts: &Options) -> UResult<()> { fn print_terminal_size(termios: &Termios, opts: &Options) -> nix::Result<()> { let speed = cfgetospeed(termios); + + // BSDs use a u32 for the baud rate, so we can simply print it. + #[cfg(any( + target_os = "freebsd", + target_os = "dragonfly", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd" + ))] + print!("speed {} baud; ", speed); + + // Other platforms need to use the baud rate enum, so printing the right value + // becomes slightly more complicated. + #[cfg(not(any( + target_os = "freebsd", + target_os = "dragonfly", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd" + )))] for (text, baud_rate) in BAUD_RATES { if *baud_rate == speed { print!("speed {} baud; ", text); @@ -190,21 +221,25 @@ fn print_terminal_size(termios: &Termios, opts: &Options) -> nix::Result<()> { print!("rows {}; columns {}; ", size.rows, size.columns); } - // For some reason the normal nix Termios struct does not expose the line, - // so we get the underlying libc::termios struct to get that information. - let libc_termios: nix::libc::termios = termios.clone().into(); - let line = libc_termios.c_line; - print!("line = {};", line); + #[cfg(any(target_os = "linux", target_os = "redox"))] + { + // For some reason the normal nix Termios struct does not expose the line, + // so we get the underlying libc::termios struct to get that information. + let libc_termios: nix::libc::termios = termios.clone().into(); + let line = libc_termios.c_line; + print!("line = {};", line); + } + println!(); Ok(()) } fn print_settings(termios: &Termios, opts: &Options) -> nix::Result<()> { print_terminal_size(termios, opts)?; - print_flags(termios, opts, &CONTROL_FLAGS); - print_flags(termios, opts, &INPUT_FLAGS); - print_flags(termios, opts, &OUTPUT_FLAGS); - print_flags(termios, opts, &LOCAL_FLAGS); + print_flags(termios, opts, CONTROL_FLAGS); + print_flags(termios, opts, INPUT_FLAGS); + print_flags(termios, opts, OUTPUT_FLAGS); + print_flags(termios, opts, LOCAL_FLAGS); Ok(()) } @@ -249,10 +284,10 @@ fn apply_setting(termios: &mut Termios, s: &str) -> ControlFlow { Some(s) => (true, s), None => (false, s), }; - apply_flag(termios, &CONTROL_FLAGS, name, remove)?; - apply_flag(termios, &INPUT_FLAGS, name, remove)?; - apply_flag(termios, &OUTPUT_FLAGS, name, remove)?; - apply_flag(termios, &LOCAL_FLAGS, name, remove)?; + apply_flag(termios, CONTROL_FLAGS, name, remove)?; + apply_flag(termios, INPUT_FLAGS, name, remove)?; + apply_flag(termios, OUTPUT_FLAGS, name, remove)?; + apply_flag(termios, LOCAL_FLAGS, name, remove)?; ControlFlow::Break(false) } From 6f6784f1137743fc0971d978b04ba51154c60a95 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 18 Aug 2022 10:52:25 +0200 Subject: [PATCH 29/44] Adjust the code after https://github.com/uutils/coreutils/pull/3832 --- src/uu/stty/src/stty.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 0f5476279..5303e3959 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -17,7 +17,7 @@ use std::io::{self, stdout}; use std::ops::ControlFlow; use std::os::unix::io::{AsRawFd, RawFd}; use uucore::error::{UResult, USimpleError}; -use uucore::{format_usage, InvalidEncodingHandling}; +use uucore::format_usage; #[cfg(not(any( target_os = "freebsd", @@ -138,8 +138,7 @@ ioctl_write_ptr_bad!( #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args - .collect_str(InvalidEncodingHandling::ConvertLossy) - .accept_any(); + .collect_lossy(); let matches = uu_app().get_matches_from(args); From 20809db4393be60c6c9103a682b43d2efb468021 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 18 Aug 2022 11:38:09 +0000 Subject: [PATCH 30/44] build(deps): bump lscolors from 0.11.1 to 0.12.0 Bumps [lscolors](https://github.com/sharkdp/lscolors) from 0.11.1 to 0.12.0. - [Release notes](https://github.com/sharkdp/lscolors/releases) - [Commits](https://github.com/sharkdp/lscolors/compare/v0.11.1...v0.12.0) --- updated-dependencies: - dependency-name: lscolors dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 8 ++++---- src/uu/ls/Cargo.toml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba035a72c..e34a25d8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1132,9 +1132,9 @@ dependencies = [ [[package]] name = "lscolors" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b3501e949531fefe2d23b2d5fb9bbb0f450e528bbfcdcd78ad04f28c3dea550" +checksum = "074bff749d092e2e818fe954952102f88e21f67fc69f4d350621aab15a1810f1" dependencies = [ "ansi_term", ] @@ -1319,9 +1319,9 @@ checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" [[package]] name = "once_cell" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" [[package]] name = "onig" diff --git a/src/uu/ls/Cargo.toml b/src/uu/ls/Cargo.toml index 98cf83547..723b284c0 100644 --- a/src/uu/ls/Cargo.toml +++ b/src/uu/ls/Cargo.toml @@ -22,9 +22,9 @@ number_prefix = "0.4" term_grid = "0.1.5" termsize = "0.1.6" glob = "0.3.0" -lscolors = { version = "0.11.0", features = ["ansi_term"] } +lscolors = { version = "0.12.0", features = ["ansi_term"] } uucore = { version = ">=0.0.8", package = "uucore", path = "../../uucore", features = ["entries", "fs"] } -once_cell = "1.13.0" +once_cell = "1.13.1" atty = "0.2" selinux = { version="0.2", optional = true } From e9e9a8166f0714422cb31f55a0a2d7e4b4351544 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Thu, 18 Aug 2022 15:20:32 +0200 Subject: [PATCH 31/44] uucore/ranges: refactor FromStr impl --- src/uucore/src/lib/mods/ranges.rs | 100 +++++++++++++----------------- 1 file changed, 44 insertions(+), 56 deletions(-) diff --git a/src/uucore/src/lib/mods/ranges.rs b/src/uucore/src/lib/mods/ranges.rs index 822c09e02..ff35b3432 100644 --- a/src/uucore/src/lib/mods/ranges.rs +++ b/src/uucore/src/lib/mods/ranges.rs @@ -20,63 +20,53 @@ pub struct Range { impl FromStr for Range { type Err = &'static str; + /// Parse a string of the form `a-b` into a `Range` + /// + /// ``` + /// use std::str::FromStr; + /// use uucore::ranges::Range; + /// assert_eq!(Range::from_str("5"), Ok(Range { low: 5, high: 5 })); + /// assert_eq!(Range::from_str("4-"), Ok(Range { low: 4, high: usize::MAX - 1 })); + /// assert_eq!(Range::from_str("-4"), Ok(Range { low: 1, high: 4 })); + /// assert_eq!(Range::from_str("2-4"), Ok(Range { low: 2, high: 4 })); + /// assert!(Range::from_str("0-4").is_err()); + /// assert!(Range::from_str("4-2").is_err()); + /// assert!(Range::from_str("-").is_err()); + /// assert!(Range::from_str("a").is_err()); + /// assert!(Range::from_str("a-b").is_err()); + /// ``` fn from_str(s: &str) -> Result { - use std::usize::MAX; - - let mut parts = s.splitn(2, '-'); - - let field = "fields and positions are numbered from 1"; - let order = "high end of range less than low end"; - let inval = "failed to parse range"; - - match (parts.next(), parts.next()) { - (Some(nm), None) => { - if let Ok(nm) = nm.parse::() { - if nm > 0 { - Ok(Self { low: nm, high: nm }) - } else { - Err(field) - } - } else { - Err(inval) - } + fn parse(s: &str) -> Result { + match s.parse::() { + Ok(0) => Err("fields and positions are numbered from 1"), + Ok(n) => Ok(n), + Err(_) => Err("failed to parse range"), } - (Some(n), Some(m)) if m.is_empty() => { - if let Ok(low) = n.parse::() { - if low > 0 { - Ok(Self { low, high: MAX - 1 }) - } else { - Err(field) - } - } else { - Err(inval) - } - } - (Some(n), Some(m)) if n.is_empty() => { - if let Ok(high) = m.parse::() { - if high > 0 { - Ok(Self { low: 1, high }) - } else { - Err(field) - } - } else { - Err(inval) - } - } - (Some(n), Some(m)) => match (n.parse::(), m.parse::()) { - (Ok(low), Ok(high)) => { - if low > 0 && low <= high { - Ok(Self { low, high }) - } else if low == 0 { - Err(field) - } else { - Err(order) - } - } - _ => Err(inval), - }, - _ => unreachable!(), } + + Ok(match s.split_once('-') { + None => { + let n = parse(s)?; + Self { low: n, high: n } + } + Some(("", "")) => return Err("invalid range with no endpoint"), + Some((low, "")) => Self { + low: parse(low)?, + high: usize::MAX - 1, + }, + Some(("", high)) => Self { + low: 1, + high: parse(high)?, + }, + Some((low, high)) => { + let (low, high) = (parse(low)?, parse(high)?); + if low <= high { + Self { low, high } + } else { + return Err("high end of range less than low end"); + } + } + }) } } @@ -109,8 +99,6 @@ impl Range { } pub fn complement(ranges: &[Range]) -> Vec { - use std::usize; - let mut complements = Vec::with_capacity(ranges.len() + 1); if !ranges.is_empty() && ranges[0].low > 1 { From 7890228f82c6c14f3528a2f8b735a275bf24b273 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Thu, 18 Aug 2022 19:45:56 +0200 Subject: [PATCH 32/44] uucore/ranges: document and test merge operation --- src/uucore/src/lib/mods/ranges.rs | 86 ++++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 6 deletions(-) diff --git a/src/uucore/src/lib/mods/ranges.rs b/src/uucore/src/lib/mods/ranges.rs index ff35b3432..319ab5b83 100644 --- a/src/uucore/src/lib/mods/ranges.rs +++ b/src/uucore/src/lib/mods/ranges.rs @@ -7,6 +7,7 @@ // spell-checker:ignore (ToDO) inval +use std::cmp::max; use std::str::FromStr; use crate::display::Quotable; @@ -72,9 +73,7 @@ impl FromStr for Range { impl Range { pub fn from_list(list: &str) -> Result, String> { - use std::cmp::max; - - let mut ranges: Vec = vec![]; + let mut ranges = Vec::new(); for item in list.split(',') { let range_item = FromStr::from_str(item) @@ -82,19 +81,28 @@ impl Range { ranges.push(range_item); } + Ok(Range::merge(ranges)) + } + + /// Merge any overlapping ranges + /// + /// Is guaranteed to return only disjoint ranges in a sorted order. + fn merge(mut ranges: Vec) -> Vec { ranges.sort(); // merge overlapping ranges for i in 0..ranges.len() { let j = i + 1; - while j < ranges.len() && ranges[j].low <= ranges[i].high { + // The +1 is a small optimization, because we can merge adjacent Ranges. + // For example (1,3) and (4,6), because in the integers, there are no + // possible values between 3 and 4, this is equivalent to (1,6). + while j < ranges.len() && ranges[j].low <= ranges[i].high + 1 { let j_high = ranges.remove(j).high; ranges[i].high = max(ranges[i].high, j_high); } } - - Ok(ranges) + ranges } } @@ -161,3 +169,69 @@ pub fn contain(ranges: &[Range], n: usize) -> bool { false } + +#[cfg(test)] +mod test { + use super::Range; + + fn m(a: Vec, b: Vec) { + assert_eq!(Range::merge(a), b); + } + + fn r(low: usize, high: usize) -> Range { + Range { low, high } + } + + #[test] + fn merging() { + // Single element + m(vec![r(1, 2)], vec![r(1, 2)]); + + // Disjoint in wrong order + m(vec![r(4, 5), r(1, 2)], vec![r(1, 2), r(4, 5)]); + + // Two elements must be merged + m(vec![r(1, 3), r(2, 4), r(6, 7)], vec![r(1, 4), r(6, 7)]); + + // Two merges and a duplicate + m( + vec![r(1, 3), r(6, 7), r(2, 4), r(6, 7)], + vec![r(1, 4), r(6, 7)], + ); + + // One giant + m( + vec![ + r(110, 120), + r(10, 20), + r(100, 200), + r(130, 140), + r(150, 160), + ], + vec![r(10, 20), r(100, 200)], + ); + + // Last one joins the previous two + m( + vec![ + r(10,20), + r(30,40), + r(20,30), + ], + vec![r(10,40)] + ); + + m( + vec![ + r(10,20), + r(30,40), + r(50,60), + r(20,30), + ], + vec![r(10,40), r(50,60)] + ); + + // Merge adjacent ranges + m(vec![r(1, 3), r(4, 6)], vec![r(1, 6)]) + } +} \ No newline at end of file From 003b483705141634358e1457ddde8dccecfb0d5a Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Thu, 18 Aug 2022 20:02:50 +0200 Subject: [PATCH 33/44] uucore/ranges: refactor and test complement --- src/uucore/src/lib/mods/ranges.rs | 89 +++++++++++++++---------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/src/uucore/src/lib/mods/ranges.rs b/src/uucore/src/lib/mods/ranges.rs index 319ab5b83..71ad38414 100644 --- a/src/uucore/src/lib/mods/ranges.rs +++ b/src/uucore/src/lib/mods/ranges.rs @@ -81,11 +81,11 @@ impl Range { ranges.push(range_item); } - Ok(Range::merge(ranges)) + Ok(Self::merge(ranges)) } /// Merge any overlapping ranges - /// + /// /// Is guaranteed to return only disjoint ranges in a sorted order. fn merge(mut ranges: Vec) -> Vec { ranges.sort(); @@ -107,36 +107,24 @@ impl Range { } pub fn complement(ranges: &[Range]) -> Vec { + let mut prev_high = 0; let mut complements = Vec::with_capacity(ranges.len() + 1); - if !ranges.is_empty() && ranges[0].low > 1 { - complements.push(Range { - low: 1, - high: ranges[0].low - 1, - }); + for range in ranges { + if range.low > prev_high + 1 { + complements.push(Range { + low: prev_high + 1, + high: range.low - 1, + }); + } + prev_high = range.high; } - let mut ranges_iter = ranges.iter().peekable(); - loop { - match (ranges_iter.next(), ranges_iter.peek()) { - (Some(left), Some(right)) => { - if left.high + 1 != right.low { - complements.push(Range { - low: left.high + 1, - high: right.low - 1, - }); - } - } - (Some(last), None) => { - if last.high < usize::MAX - 1 { - complements.push(Range { - low: last.high + 1, - high: usize::MAX - 1, - }); - } - } - _ => break, - } + if prev_high < usize::MAX - 1 { + complements.push(Range { + low: prev_high + 1, + high: usize::MAX - 1, + }); } complements @@ -172,7 +160,7 @@ pub fn contain(ranges: &[Range], n: usize) -> bool { #[cfg(test)] mod test { - use super::Range; + use super::{complement, Range}; fn m(a: Vec, b: Vec) { assert_eq!(Range::merge(a), b); @@ -181,7 +169,7 @@ mod test { fn r(low: usize, high: usize) -> Range { Range { low, high } } - + #[test] fn merging() { // Single element @@ -212,26 +200,35 @@ mod test { ); // Last one joins the previous two - m( - vec![ - r(10,20), - r(30,40), - r(20,30), - ], - vec![r(10,40)] - ); + m(vec![r(10, 20), r(30, 40), r(20, 30)], vec![r(10, 40)]); m( - vec![ - r(10,20), - r(30,40), - r(50,60), - r(20,30), - ], - vec![r(10,40), r(50,60)] + vec![r(10, 20), r(30, 40), r(50, 60), r(20, 30)], + vec![r(10, 40), r(50, 60)], ); // Merge adjacent ranges m(vec![r(1, 3), r(4, 6)], vec![r(1, 6)]) } -} \ No newline at end of file + + #[test] + fn complementing() { + // Simple + assert_eq!(complement(&[r(3, 4)]), vec![r(1, 2), r(5, usize::MAX - 1)]); + + // With start + assert_eq!( + complement(&[r(1, 3), r(6, 10)]), + vec![r(4, 5), r(11, usize::MAX - 1)] + ); + + // With end + assert_eq!( + complement(&[r(2, 4), r(6, usize::MAX - 1)]), + vec![r(1, 1), r(5, 5)] + ); + + // With start and end + assert_eq!(complement(&[r(1, 4), r(6, usize::MAX - 1)]), vec![r(5, 5)]); + } +} From f0cd3a0599c73b87a752c1e56636cc24362bd0ab Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Wed, 17 Aug 2022 19:06:36 +0300 Subject: [PATCH 34/44] deny: removed hashbrown from checking duplicate crates, indexmap requires new version of hashbrown as well --- deny.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/deny.toml b/deny.toml index fb076dd5e..e35e9b2e4 100644 --- a/deny.toml +++ b/deny.toml @@ -70,8 +70,6 @@ skip = [ { name = "arrayvec", version = "=0.7.2" }, # flimit/unix_socket { name = "cfg-if", version = "=0.1.10" }, - # indexmap - { name = "hashbrown", version = "=0.11.2" }, # kernel32-sys { name = "winapi", version = "=0.2.8" }, # bindgen 0.59.2 From 67ae68a6cf1d839925ce8bd83efcc423cdbcd878 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Fri, 19 Aug 2022 12:28:13 +0300 Subject: [PATCH 35/44] dependecies: make winapi dependency only for windows, bump platform-info crate version dependency --- Cargo.lock | 4 ++-- src/uu/arch/Cargo.toml | 2 +- src/uu/hostname/Cargo.toml | 2 ++ src/uu/sync/Cargo.toml | 2 ++ src/uu/uname/Cargo.toml | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f4f3a9807..242014d20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1489,9 +1489,9 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "platform-info" -version = "0.2.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84332c4de03d567e6f5ea143e35e63ceed534a34f768218aabf57879d7edf2a0" +checksum = "95f26dfd50c79dacf549a8a784734fff83a5e42736487464d782fc8a3a2f5563" dependencies = [ "libc", "winapi 0.3.9", diff --git a/src/uu/arch/Cargo.toml b/src/uu/arch/Cargo.toml index a7e08f9bc..f344144fe 100644 --- a/src/uu/arch/Cargo.toml +++ b/src/uu/arch/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/arch.rs" [dependencies] -platform-info = "0.2" +platform-info = "1.0.0" clap = { version = "3.2", features = ["wrap_help", "cargo"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } diff --git a/src/uu/hostname/Cargo.toml b/src/uu/hostname/Cargo.toml index 6d866c3ba..8baebc3a4 100644 --- a/src/uu/hostname/Cargo.toml +++ b/src/uu/hostname/Cargo.toml @@ -18,6 +18,8 @@ path = "src/hostname.rs" clap = { version = "3.2", features = ["wrap_help", "cargo"] } hostname = { version = "0.3", features = ["set"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["wide"] } + +[target.'cfg(target_os = "windows")'.dependencies] winapi = { version="0.3", features=["sysinfoapi", "winsock2"] } [[bin]] diff --git a/src/uu/sync/Cargo.toml b/src/uu/sync/Cargo.toml index b882af28b..403076d6a 100644 --- a/src/uu/sync/Cargo.toml +++ b/src/uu/sync/Cargo.toml @@ -18,6 +18,8 @@ path = "src/sync.rs" clap = { version = "3.2", features = ["wrap_help", "cargo"] } libc = "0.2.126" uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["wide"] } + +[target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["errhandlingapi", "fileapi", "handleapi", "std", "winbase", "winerror"] } [[bin]] diff --git a/src/uu/uname/Cargo.toml b/src/uu/uname/Cargo.toml index 6400abd1e..11daf9f00 100644 --- a/src/uu/uname/Cargo.toml +++ b/src/uu/uname/Cargo.toml @@ -16,7 +16,7 @@ path = "src/uname.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -platform-info = "0.2" +platform-info = "1.0.0" uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } [[bin]] From 0e14e1ded08b3232b7c936ce157f61e059379d42 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 19 Aug 2022 12:30:31 +0200 Subject: [PATCH 36/44] stty: add cfg guards for flags that don't exist on BSD fix another flag --- src/uu/stty/src/flags.rs | 134 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/src/uu/stty/src/flags.rs b/src/uu/stty/src/flags.rs index ad24fef30..2c3f00eec 100644 --- a/src/uu/stty/src/flags.rs +++ b/src/uu/stty/src/flags.rs @@ -57,6 +57,7 @@ pub const INPUT_FLAGS: &[Flag] = &[ // Flag::new("iuclc", I::IUCLC), Flag::new("ixany", I::IXANY), Flag::new("imaxbel", I::IMAXBEL).sane(), + #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] Flag::new("iutf8", I::IUTF8), ]; @@ -73,23 +74,156 @@ pub const OUTPUT_FLAGS: &[Flag] = &[ Flag::new("onlcr", O::ONLCR).sane(), Flag::new("onocr", O::ONOCR), Flag::new("onlret", O::ONLRET), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new("ofill", O::OFILL), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new("ofdel", O::OFDEL), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("nl0", O::NL0, O::NLDLY).sane(), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("nl1", O::NL1, O::NLDLY), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("cr0", O::CR0, O::CRDLY).sane(), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("cr1", O::CR1, O::CRDLY), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("cr2", O::CR2, O::CRDLY), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("cr3", O::CR3, O::CRDLY), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("tab0", O::TAB0, O::TABDLY).sane(), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("tab1", O::TAB1, O::TABDLY), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("tab2", O::TAB2, O::TABDLY), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("tab3", O::TAB3, O::TABDLY), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("bs0", O::BS0, O::BSDLY).sane(), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("bs1", O::BS1, O::BSDLY), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("vt0", O::VT0, O::VTDLY).sane(), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("vt1", O::VT1, O::VTDLY), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("ff0", O::FF0, O::FFDLY).sane(), + #[cfg(any( + target_os = "android", + target_os = "haiku", + target_os = "ios", + target_os = "linux", + target_os = "macos" + ))] Flag::new_grouped("ff1", O::FF1, O::FFDLY), ]; From a1250ec4620190d6d4f231c12d727f2b4f36b331 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 19 Aug 2022 12:34:51 +0200 Subject: [PATCH 37/44] stty: fix nix version --- src/uu/stty/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/stty/Cargo.toml b/src/uu/stty/Cargo.toml index d39786494..919dd288b 100644 --- a/src/uu/stty/Cargo.toml +++ b/src/uu/stty/Cargo.toml @@ -17,7 +17,7 @@ path = "src/stty.rs" [dependencies] clap = { version = "3.1", features = ["wrap_help", "cargo"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } -nix = { version="0.24.1", features = ["term"] } +nix = { version="0.25", features = ["term"] } [[bin]] name = "stty" From c269a386eb59fe454c2f8982ff1f6d26bf7e60f3 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 19 Aug 2022 13:12:43 +0200 Subject: [PATCH 38/44] stty: cargo fmt --- src/uu/stty/src/stty.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 5303e3959..23c1c357c 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -137,8 +137,7 @@ ioctl_write_ptr_bad!( #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = args - .collect_lossy(); + let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); From 6193cdbba8fb506f58783eade2dae2a6dcb06ba8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Aug 2022 12:22:35 +0000 Subject: [PATCH 39/44] build(deps): bump libc from 0.2.131 to 0.2.132 Bumps [libc](https://github.com/rust-lang/libc) from 0.2.131 to 0.2.132. - [Release notes](https://github.com/rust-lang/libc/releases) - [Commits](https://github.com/rust-lang/libc/compare/0.2.131...0.2.132) --- updated-dependencies: - dependency-name: libc dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- src/uu/chmod/Cargo.toml | 2 +- src/uu/cp/Cargo.toml | 2 +- src/uu/hostid/Cargo.toml | 2 +- src/uu/logname/Cargo.toml | 2 +- src/uu/mkfifo/Cargo.toml | 2 +- src/uu/mknod/Cargo.toml | 2 +- src/uu/nice/Cargo.toml | 2 +- src/uu/nohup/Cargo.toml | 2 +- src/uu/nproc/Cargo.toml | 2 +- src/uu/pathchk/Cargo.toml | 2 +- src/uu/rmdir/Cargo.toml | 2 +- src/uu/sync/Cargo.toml | 2 +- src/uu/tail/Cargo.toml | 2 +- src/uu/tee/Cargo.toml | 2 +- src/uu/test/Cargo.toml | 2 +- src/uu/timeout/Cargo.toml | 2 +- src/uu/whoami/Cargo.toml | 2 +- src/uu/yes/Cargo.toml | 2 +- src/uucore/Cargo.toml | 2 +- 20 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 242014d20..2fbc4b399 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1097,9 +1097,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.131" +version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04c3b4822ccebfa39c02fc03d1534441b22ead323fa0f48bb7ddd8e6ba076a40" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] name = "libloading" diff --git a/src/uu/chmod/Cargo.toml b/src/uu/chmod/Cargo.toml index 185150678..688b99af0 100644 --- a/src/uu/chmod/Cargo.toml +++ b/src/uu/chmod/Cargo.toml @@ -16,7 +16,7 @@ path = "src/chmod.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["fs", "mode"] } [[bin]] diff --git a/src/uu/cp/Cargo.toml b/src/uu/cp/Cargo.toml index bc5465c3d..c50d37bcf 100644 --- a/src/uu/cp/Cargo.toml +++ b/src/uu/cp/Cargo.toml @@ -21,7 +21,7 @@ path = "src/cp.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } filetime = "0.2" -libc = "0.2.126" +libc = "0.2.132" quick-error = "2.0.1" selinux = { version="0.2", optional=true } uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["entries", "fs", "perms", "mode"] } diff --git a/src/uu/hostid/Cargo.toml b/src/uu/hostid/Cargo.toml index bb8415312..62744d8b0 100644 --- a/src/uu/hostid/Cargo.toml +++ b/src/uu/hostid/Cargo.toml @@ -16,7 +16,7 @@ path = "src/hostid.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } [[bin]] diff --git a/src/uu/logname/Cargo.toml b/src/uu/logname/Cargo.toml index 1e9545399..32c017444 100644 --- a/src/uu/logname/Cargo.toml +++ b/src/uu/logname/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/logname.rs" [dependencies] -libc = "0.2.126" +libc = "0.2.132" clap = { version = "3.2", features = ["wrap_help", "cargo"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } diff --git a/src/uu/mkfifo/Cargo.toml b/src/uu/mkfifo/Cargo.toml index 022b104bd..4f7341aa4 100644 --- a/src/uu/mkfifo/Cargo.toml +++ b/src/uu/mkfifo/Cargo.toml @@ -16,7 +16,7 @@ path = "src/mkfifo.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } [[bin]] diff --git a/src/uu/mknod/Cargo.toml b/src/uu/mknod/Cargo.toml index c9bb5bbc0..1329d0b6a 100644 --- a/src/uu/mknod/Cargo.toml +++ b/src/uu/mknod/Cargo.toml @@ -17,7 +17,7 @@ path = "src/mknod.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "^0.2.126" +libc = "^0.2.132" uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["mode"] } [[bin]] diff --git a/src/uu/nice/Cargo.toml b/src/uu/nice/Cargo.toml index 650a5cbf8..30d5b5b13 100644 --- a/src/uu/nice/Cargo.toml +++ b/src/uu/nice/Cargo.toml @@ -16,7 +16,7 @@ path = "src/nice.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" nix = { version = "0.25", default-features = false } uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } diff --git a/src/uu/nohup/Cargo.toml b/src/uu/nohup/Cargo.toml index 18a319811..175df193f 100644 --- a/src/uu/nohup/Cargo.toml +++ b/src/uu/nohup/Cargo.toml @@ -16,7 +16,7 @@ path = "src/nohup.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" atty = "0.2" uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["fs"] } diff --git a/src/uu/nproc/Cargo.toml b/src/uu/nproc/Cargo.toml index d711df005..23122de60 100644 --- a/src/uu/nproc/Cargo.toml +++ b/src/uu/nproc/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/nproc.rs" [dependencies] -libc = "0.2.126" +libc = "0.2.132" num_cpus = "1.10" clap = { version = "3.2", features = ["wrap_help", "cargo"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["fs"] } diff --git a/src/uu/pathchk/Cargo.toml b/src/uu/pathchk/Cargo.toml index ec09b0f25..fba51708c 100644 --- a/src/uu/pathchk/Cargo.toml +++ b/src/uu/pathchk/Cargo.toml @@ -16,7 +16,7 @@ path = "src/pathchk.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } [[bin]] diff --git a/src/uu/rmdir/Cargo.toml b/src/uu/rmdir/Cargo.toml index fdc3ba6a1..dd2d3ad6e 100644 --- a/src/uu/rmdir/Cargo.toml +++ b/src/uu/rmdir/Cargo.toml @@ -17,7 +17,7 @@ path = "src/rmdir.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } -libc = "0.2.126" +libc = "0.2.132" [[bin]] name = "rmdir" diff --git a/src/uu/sync/Cargo.toml b/src/uu/sync/Cargo.toml index 403076d6a..0f1228f76 100644 --- a/src/uu/sync/Cargo.toml +++ b/src/uu/sync/Cargo.toml @@ -16,7 +16,7 @@ path = "src/sync.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["wide"] } [target.'cfg(target_os = "windows")'.dependencies] diff --git a/src/uu/tail/Cargo.toml b/src/uu/tail/Cargo.toml index 8c51de5fd..9b1d0d8fa 100644 --- a/src/uu/tail/Cargo.toml +++ b/src/uu/tail/Cargo.toml @@ -17,7 +17,7 @@ path = "src/tail.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" notify = { version = "=5.0.0-pre.16", features=["macos_kqueue"]} uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["ringbuffer", "lines"] } diff --git a/src/uu/tee/Cargo.toml b/src/uu/tee/Cargo.toml index 66a0e15fc..4cdbf8c10 100644 --- a/src/uu/tee/Cargo.toml +++ b/src/uu/tee/Cargo.toml @@ -16,7 +16,7 @@ path = "src/tee.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" retain_mut = "=0.1.7" # ToDO: [2021-01-01; rivy; maint/MinSRV] ~ v0.1.5 uses const generics which aren't stabilized until rust v1.51.0 uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["libc"] } diff --git a/src/uu/test/Cargo.toml b/src/uu/test/Cargo.toml index a774ddaa2..c4cb95d55 100644 --- a/src/uu/test/Cargo.toml +++ b/src/uu/test/Cargo.toml @@ -16,7 +16,7 @@ path = "src/test.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } [target.'cfg(target_os = "redox")'.dependencies] diff --git a/src/uu/timeout/Cargo.toml b/src/uu/timeout/Cargo.toml index b87f96a39..901a37c54 100644 --- a/src/uu/timeout/Cargo.toml +++ b/src/uu/timeout/Cargo.toml @@ -16,7 +16,7 @@ path = "src/timeout.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" nix = { version = "0.25", default-features = false, features = ["signal"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["process", "signals"] } diff --git a/src/uu/whoami/Cargo.toml b/src/uu/whoami/Cargo.toml index 3ff0e9e67..89ffacb02 100644 --- a/src/uu/whoami/Cargo.toml +++ b/src/uu/whoami/Cargo.toml @@ -22,7 +22,7 @@ uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=[ winapi = { version = "0.3", features = ["lmcons"] } [target.'cfg(unix)'.dependencies] -libc = "0.2.126" +libc = "0.2.132" [[bin]] name = "whoami" diff --git a/src/uu/yes/Cargo.toml b/src/uu/yes/Cargo.toml index fcac80f2c..fedd3865c 100644 --- a/src/uu/yes/Cargo.toml +++ b/src/uu/yes/Cargo.toml @@ -16,7 +16,7 @@ path = "src/yes.rs" [dependencies] clap = { version = "3.2", features = ["wrap_help", "cargo"] } -libc = "0.2.126" +libc = "0.2.132" uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["pipes"] } [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index 73ee31138..9d76f50d3 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -32,7 +32,7 @@ time = { version="<= 0.3", optional=true, features = ["formatting", "local-offse data-encoding = { version="2.1", optional=true } data-encoding-macro = { version="0.1.12", optional=true } z85 = { version="3.0.5", optional=true } -libc = { version="0.2.126", optional=true } +libc = { version="0.2.132", optional=true } once_cell = "1.13.1" os_display = "0.1.3" From 80b1ed13e5fd2188b3468457176c8e6d702b0b7c Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 19 Aug 2022 14:33:01 +0200 Subject: [PATCH 40/44] maintenance: remove redundant examples folder These examples only duplicated the multicall binary via an include and are therefore not necessary. --- examples/busybox-core.rs | 1 - examples/uuc.rs | 1 - 2 files changed, 2 deletions(-) delete mode 100644 examples/busybox-core.rs delete mode 100644 examples/uuc.rs diff --git a/examples/busybox-core.rs b/examples/busybox-core.rs deleted file mode 100644 index 89dd1848d..000000000 --- a/examples/busybox-core.rs +++ /dev/null @@ -1 +0,0 @@ -include!("../src/bin/coreutils.rs"); diff --git a/examples/uuc.rs b/examples/uuc.rs deleted file mode 100644 index 89dd1848d..000000000 --- a/examples/uuc.rs +++ /dev/null @@ -1 +0,0 @@ -include!("../src/bin/coreutils.rs"); From afda6be8c7ac0b970bbe052dbdfe55cab7a54946 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sat, 20 Aug 2022 01:02:53 +0200 Subject: [PATCH 41/44] Update clap from 3.2.15 to 3.2.17 --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index e5d317659..5f1d64758 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2913,7 +2913,7 @@ dependencies = [ name = "uu_stty" version = "0.0.14" dependencies = [ - "clap 3.2.15", + "clap 3.2.17", "nix", "uucore", ] From 62b1b7cfb271252174d0dba70184254da0ed8b23 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sat, 20 Aug 2022 08:19:11 +0200 Subject: [PATCH 42/44] Replace deprecated values_of_os() with get_many() --- src/uu/chcon/src/chcon.rs | 2 +- src/uu/dir/src/dir.rs | 3 ++- src/uu/hashsum/src/hashsum.rs | 4 ++-- src/uu/link/src/link.rs | 3 ++- src/uu/ls/src/ls.rs | 2 +- src/uu/mkdir/src/mkdir.rs | 10 +++++++--- src/uu/mv/src/mv.rs | 2 +- src/uu/rmdir/src/rmdir.rs | 3 ++- src/uu/runcon/src/runcon.rs | 2 +- src/uu/sort/src/sort.rs | 4 ++-- src/uu/stat/src/stat.rs | 2 +- src/uu/touch/src/touch.rs | 3 ++- src/uu/users/src/users.rs | 3 ++- src/uu/vdir/src/vdir.rs | 3 ++- src/uu/wc/src/wc.rs | 6 +++--- 15 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index ee6f6e598..7b72fd41a 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -357,7 +357,7 @@ fn parse_command_line(config: clap::Command, args: impl uucore::Args) -> Result< // By default, do not preserve root. let preserve_root = matches.contains_id(options::preserve_root::PRESERVE_ROOT); - let mut files = matches.values_of_os("FILE").unwrap_or_default(); + let mut files = matches.get_many::("FILE").unwrap_or_default(); let mode = if let Some(path) = matches.value_of_os(options::REFERENCE) { CommandLineMode::ReferenceBased { diff --git a/src/uu/dir/src/dir.rs b/src/uu/dir/src/dir.rs index 2f51395f2..22932d9ae 100644 --- a/src/uu/dir/src/dir.rs +++ b/src/uu/dir/src/dir.rs @@ -6,6 +6,7 @@ // * that was distributed with this source code. use clap::Command; +use std::ffi::OsString; use std::path::Path; use uu_ls::{options, Config, Format}; use uucore::error::UResult; @@ -55,7 +56,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } let locs = matches - .values_of_os(options::PATHS) + .get_many::(options::PATHS) .map(|v| v.map(Path::new).collect()) .unwrap_or_else(|| vec![Path::new(".")]); diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 3d8ba8d41..a2a33561f 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -320,8 +320,8 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { warn, }; - match matches.values_of_os("FILE") { - Some(files) => hashsum(opts, files), + match matches.get_many::("FILE") { + Some(files) => hashsum(opts, files.map(|f| f.as_os_str())), None => hashsum(opts, iter::once(OsStr::new("-"))), } } diff --git a/src/uu/link/src/link.rs b/src/uu/link/src/link.rs index 1fc0c49ce..fe83a55f6 100644 --- a/src/uu/link/src/link.rs +++ b/src/uu/link/src/link.rs @@ -5,6 +5,7 @@ // * For the full copyright and license information, please view the LICENSE // * file that was distributed with this source code. use clap::{crate_version, Arg, Command}; +use std::ffi::OsString; use std::fs::hard_link; use std::path::Path; use uucore::display::Quotable; @@ -23,7 +24,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().get_matches_from(args); let files: Vec<_> = matches - .values_of_os(options::FILES) + .get_many::(options::FILES) .unwrap_or_default() .collect(); let old = Path::new(files[0]); diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 9a3f6ac89..dada67f21 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -898,7 +898,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let config = Config::from(&matches)?; let locs = matches - .values_of_os(options::PATHS) + .get_many::(options::PATHS) .map(|v| v.map(Path::new).collect()) .unwrap_or_else(|| vec![Path::new(".")]); diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 3f7cbf1b9..b66537b2f 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -10,7 +10,9 @@ #[macro_use] extern crate uucore; -use clap::{crate_version, Arg, ArgMatches, Command, OsValues}; +use clap::parser::ValuesRef; +use clap::{crate_version, Arg, ArgMatches, Command}; +use std::ffi::OsString; use std::path::{Path, PathBuf}; #[cfg(not(windows))] use uucore::error::FromIo; @@ -95,7 +97,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // " of each created directory to CTX"), let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); - let dirs = matches.values_of_os(options::DIRS).unwrap_or_default(); + let dirs = matches + .get_many::(options::DIRS) + .unwrap_or_default(); let verbose = matches.contains_id(options::VERBOSE); let recursive = matches.contains_id(options::PARENTS); @@ -143,7 +147,7 @@ pub fn uu_app<'a>() -> Command<'a> { /** * Create the list of new directories */ -fn exec(dirs: OsValues, recursive: bool, mode: u32, verbose: bool) -> UResult<()> { +fn exec(dirs: ValuesRef, recursive: bool, mode: u32, verbose: bool) -> UResult<()> { for dir in dirs { // Special case to match GNU's behavior: // mkdir -p foo/. should work and just create foo/ diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 8a681704f..a29b8fca9 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -92,7 +92,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } let files: Vec = matches - .values_of_os(ARG_FILES) + .get_many::(ARG_FILES) .unwrap_or_default() .map(|v| v.to_os_string()) .collect(); diff --git a/src/uu/rmdir/src/rmdir.rs b/src/uu/rmdir/src/rmdir.rs index e4ff74ddf..76c439d96 100644 --- a/src/uu/rmdir/src/rmdir.rs +++ b/src/uu/rmdir/src/rmdir.rs @@ -11,6 +11,7 @@ extern crate uucore; use clap::{crate_version, Arg, Command}; +use std::ffi::OsString; use std::fs::{read_dir, remove_dir}; use std::io; use std::path::Path; @@ -40,7 +41,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }; for path in matches - .values_of_os(ARG_DIRS) + .get_many::(ARG_DIRS) .unwrap_or_default() .map(Path::new) { diff --git a/src/uu/runcon/src/runcon.rs b/src/uu/runcon/src/runcon.rs index 31858d3f7..6035d049c 100644 --- a/src/uu/runcon/src/runcon.rs +++ b/src/uu/runcon/src/runcon.rs @@ -212,7 +212,7 @@ fn parse_command_line(config: Command, args: impl uucore::Args) -> Result