diff --git a/Cargo.lock b/Cargo.lock index a12ec25c9..0586e8f62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1145,9 +1145,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.135" +version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "libloading" @@ -2076,21 +2076,32 @@ dependencies = [ [[package]] name = "time" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d634a985c4d4238ec39cacaed2e7ae552fbd3c476b552c1deac3021b7d7eaf0c" +checksum = "0fab5c8b9980850e06d92ddbe3ab839c062c801f3927c0fb8abd6fc8e918fbca" dependencies = [ "itoa", "libc", "num_threads", + "serde", + "time-core", "time-macros", ] [[package]] -name = "time-macros" -version = "0.2.4" +name = "time-core" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + +[[package]] +name = "time-macros" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bb801831d812c562ae7d2bfb531f26e66e4e1f6b17307ba4149c5064710e5b" +dependencies = [ + "time-core", +] [[package]] name = "typenum" diff --git a/out b/out deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index 1742ca1a2..2abf8d40a 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -100,7 +100,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } CommandLineMode::ContextBased { context } => { - let c_context = match os_str_to_c_string(&context) { + let c_context = match os_str_to_c_string(context) { Ok(context) => context, Err(_r) => { @@ -198,7 +198,7 @@ pub fn uu_app() -> Command { .long(options::REFERENCE) .value_name("RFILE") .value_hint(clap::ValueHint::FilePath) - .conflicts_with_all(&[options::USER, options::ROLE, options::TYPE, options::RANGE]) + .conflicts_with_all([options::USER, options::ROLE, options::TYPE, options::RANGE]) .help( "Use security context of RFILE, rather than specifying \ a CONTEXT value.", @@ -249,7 +249,7 @@ pub fn uu_app() -> Command { Arg::new(options::sym_links::FOLLOW_ARG_DIR_SYM_LINK) .short('H') .requires(options::RECURSIVE) - .overrides_with_all(&[ + .overrides_with_all([ options::sym_links::FOLLOW_DIR_SYM_LINKS, options::sym_links::NO_FOLLOW_SYM_LINKS, ]) @@ -263,7 +263,7 @@ pub fn uu_app() -> Command { Arg::new(options::sym_links::FOLLOW_DIR_SYM_LINKS) .short('L') .requires(options::RECURSIVE) - .overrides_with_all(&[ + .overrides_with_all([ options::sym_links::FOLLOW_ARG_DIR_SYM_LINK, options::sym_links::NO_FOLLOW_SYM_LINKS, ]) @@ -277,7 +277,7 @@ pub fn uu_app() -> Command { Arg::new(options::sym_links::NO_FOLLOW_SYM_LINKS) .short('P') .requires(options::RECURSIVE) - .overrides_with_all(&[ + .overrides_with_all([ options::sym_links::FOLLOW_ARG_DIR_SYM_LINK, options::sym_links::FOLLOW_DIR_SYM_LINKS, ]) diff --git a/src/uu/chgrp/src/chgrp.rs b/src/uu/chgrp/src/chgrp.rs index a97f6f1ef..3b8d0bab0 100644 --- a/src/uu/chgrp/src/chgrp.rs +++ b/src/uu/chgrp/src/chgrp.rs @@ -146,7 +146,7 @@ pub fn uu_app() -> Command { Arg::new(options::traverse::NO_TRAVERSE) .short(options::traverse::NO_TRAVERSE.chars().next().unwrap()) .help("do not traverse any symbolic links (default)") - .overrides_with_all(&[options::traverse::TRAVERSE, options::traverse::EVERY]) + .overrides_with_all([options::traverse::TRAVERSE, options::traverse::EVERY]) .action(ArgAction::SetTrue), ) .arg( diff --git a/src/uu/chmod/Cargo.toml b/src/uu/chmod/Cargo.toml index c794ad821..adb72a256 100644 --- a/src/uu/chmod/Cargo.toml +++ b/src/uu/chmod/Cargo.toml @@ -16,7 +16,7 @@ path = "src/chmod.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["fs", "mode"] } [[bin]] diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index d99516d92..b2a0dcd85 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -156,21 +156,21 @@ pub fn uu_app() -> Command { Arg::new(options::traverse::TRAVERSE) .short(options::traverse::TRAVERSE.chars().next().unwrap()) .help("if a command line argument is a symbolic link to a directory, traverse it") - .overrides_with_all(&[options::traverse::EVERY, options::traverse::NO_TRAVERSE]) + .overrides_with_all([options::traverse::EVERY, options::traverse::NO_TRAVERSE]) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::traverse::EVERY) .short(options::traverse::EVERY.chars().next().unwrap()) .help("traverse every symbolic link to a directory encountered") - .overrides_with_all(&[options::traverse::TRAVERSE, options::traverse::NO_TRAVERSE]) + .overrides_with_all([options::traverse::TRAVERSE, options::traverse::NO_TRAVERSE]) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::traverse::NO_TRAVERSE) .short(options::traverse::NO_TRAVERSE.chars().next().unwrap()) .help("do not traverse any symbolic links (default)") - .overrides_with_all(&[options::traverse::TRAVERSE, options::traverse::EVERY]) + .overrides_with_all([options::traverse::TRAVERSE, options::traverse::EVERY]) .action(ArgAction::SetTrue), ) .arg( @@ -246,6 +246,19 @@ fn parse_spec(spec: &str, sep: char) -> UResult<(Option, Option)> { } else { None }; + + if user.chars().next().map(char::is_numeric).unwrap_or(false) + && group.is_empty() + && spec != user + { + // if the arg starts with an id numeric value, the group isn't set but the separator is provided, + // we should fail with an error + return Err(USimpleError::new( + 1, + format!("invalid spec: {}", spec.quote()), + )); + } + Ok((uid, gid)) } diff --git a/src/uu/cp/Cargo.toml b/src/uu/cp/Cargo.toml index 15ce7c8f5..b54e68464 100644 --- a/src/uu/cp/Cargo.toml +++ b/src/uu/cp/Cargo.toml @@ -21,7 +21,7 @@ path = "src/cp.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } filetime = "0.2" -libc = "0.2.135" +libc = "0.2.137" quick-error = "2.0.1" selinux = { version="0.3", optional=true } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["entries", "fs", "perms", "mode"] } diff --git a/src/uu/cp/src/copydir.rs b/src/uu/cp/src/copydir.rs index e0d6e96db..3527e4827 100644 --- a/src/uu/cp/src/copydir.rs +++ b/src/uu/cp/src/copydir.rs @@ -66,7 +66,7 @@ fn get_local_to_root_parent( adjust_canonicalization(path), adjust_canonicalization(parent), ); - let path = path.strip_prefix(&parent)?; + let path = path.strip_prefix(parent)?; Ok(path.to_path_buf()) } None => Ok(path.to_path_buf()), @@ -303,6 +303,27 @@ pub(crate) fn copy_directory( .into()); } + // If in `--parents` mode, create all the necessary ancestor directories. + // + // For example, if the command is `cp --parents a/b/c d`, that + // means we need to copy the two ancestor directories first: + // + // a -> d/a + // a/b -> d/a/b + // + let tmp = if options.parents { + if let Some(parent) = root.parent() { + let new_target = target.join(parent); + std::fs::create_dir_all(&new_target)?; + new_target + } else { + target.to_path_buf() + } + } else { + target.to_path_buf() + }; + let target = tmp.as_path(); + let mut hard_links: Vec<(String, u64)> = vec![]; let preserve_hard_links = options.preserve_hard_links(); diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 299eca9cf..f0e217b17 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -427,7 +427,7 @@ pub fn uu_app() -> Command { )) .num_args(0..) .value_name("ATTR_LIST") - .overrides_with_all(&[ + .overrides_with_all([ options::ARCHIVE, options::PRESERVE_DEFAULT_ATTRIBUTES, options::NO_PRESERVE, @@ -443,7 +443,7 @@ pub fn uu_app() -> Command { Arg::new(options::PRESERVE_DEFAULT_ATTRIBUTES) .short('p') .long(options::PRESERVE_DEFAULT_ATTRIBUTES) - .overrides_with_all(&[options::PRESERVE, options::NO_PRESERVE, options::ARCHIVE]) + .overrides_with_all([options::PRESERVE, options::NO_PRESERVE, options::ARCHIVE]) .help("same as --preserve=mode,ownership(unix only),timestamps") .action(ArgAction::SetTrue), ) @@ -451,7 +451,7 @@ pub fn uu_app() -> Command { Arg::new(options::NO_PRESERVE) .long(options::NO_PRESERVE) .value_name("ATTR_LIST") - .overrides_with_all(&[ + .overrides_with_all([ options::PRESERVE_DEFAULT_ATTRIBUTES, options::PRESERVE, options::ARCHIVE, @@ -492,7 +492,7 @@ pub fn uu_app() -> Command { Arg::new(options::ARCHIVE) .short('a') .long(options::ARCHIVE) - .overrides_with_all(&[ + .overrides_with_all([ options::PRESERVE_DEFAULT_ATTRIBUTES, options::PRESERVE, options::NO_PRESERVE, @@ -1146,7 +1146,16 @@ fn copy_attribute(source: &Path, dest: &Path, attribute: &Attribute) -> CopyResu } #[cfg(not(unix))] { - return Err("XAttrs are only supported on unix.".to_string().into()); + // The documentation for GNU cp states: + // + // > Try to preserve SELinux security context and + // > extended attributes (xattr), but ignore any failure + // > to do that and print no corresponding diagnostic. + // + // so we simply do nothing here. + // + // TODO Silently ignore failures in the `#[cfg(unix)]` + // block instead of terminating immediately on errors. } } }; @@ -1255,6 +1264,12 @@ fn copy_file( symlinked_files: &mut HashSet, source_in_command_line: bool, ) -> CopyResult<()> { + if options.update && options.overwrite == OverwriteMode::Interactive(ClobberMode::Standard) { + // `cp -i --update old new` when `new` exists doesn't copy anything + // and exit with 0 + return Ok(()); + } + if file_or_link_exists(dest) { handle_existing_dest(source, dest, options, source_in_command_line)?; } diff --git a/src/uu/dd/src/parseargs/unit_tests.rs b/src/uu/dd/src/parseargs/unit_tests.rs index 18eeb33a2..7084f8114 100644 --- a/src/uu/dd/src/parseargs/unit_tests.rs +++ b/src/uu/dd/src/parseargs/unit_tests.rs @@ -86,7 +86,7 @@ fn unimplemented_flags_should_error() { fn test_status_level_absent() { let args = &["if=foo.file", "of=bar.file"]; - assert_eq!(Parser::new().parse(args).unwrap().status, None) + assert_eq!(Parser::new().parse(args).unwrap().status, None); } #[test] @@ -96,7 +96,7 @@ fn test_status_level_none() { assert_eq!( Parser::new().parse(args).unwrap().status, Some(StatusLevel::None) - ) + ); } #[test] diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 8d26bc6f8..8cefd642f 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -509,7 +509,7 @@ pub fn uu_app() -> Command { .short('B') .long("block-size") .value_name("SIZE") - .overrides_with_all(&[OPT_KILO, OPT_BLOCKSIZE]) + .overrides_with_all([OPT_KILO, OPT_BLOCKSIZE]) .help( "scale sizes by SIZE before printing them; e.g.\ '-BM' prints sizes in units of 1,048,576 bytes", @@ -526,7 +526,7 @@ pub fn uu_app() -> Command { Arg::new(OPT_HUMAN_READABLE_BINARY) .short('h') .long("human-readable") - .overrides_with_all(&[OPT_HUMAN_READABLE_DECIMAL, OPT_HUMAN_READABLE_BINARY]) + .overrides_with_all([OPT_HUMAN_READABLE_DECIMAL, OPT_HUMAN_READABLE_BINARY]) .help("print sizes in human readable format (e.g., 1K 234M 2G)") .action(ArgAction::SetTrue), ) @@ -534,7 +534,7 @@ pub fn uu_app() -> Command { Arg::new(OPT_HUMAN_READABLE_DECIMAL) .short('H') .long("si") - .overrides_with_all(&[OPT_HUMAN_READABLE_BINARY, OPT_HUMAN_READABLE_DECIMAL]) + .overrides_with_all([OPT_HUMAN_READABLE_BINARY, OPT_HUMAN_READABLE_DECIMAL]) .help("likewise, but use powers of 1000 not 1024") .action(ArgAction::SetTrue), ) @@ -550,7 +550,7 @@ pub fn uu_app() -> Command { Arg::new(OPT_KILO) .short('k') .help("like --block-size=1K") - .overrides_with_all(&[OPT_BLOCKSIZE, OPT_KILO]) + .overrides_with_all([OPT_BLOCKSIZE, OPT_KILO]) .action(ArgAction::SetTrue), ) .arg( @@ -564,7 +564,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(OPT_NO_SYNC) .long("no-sync") - .overrides_with_all(&[OPT_SYNC, OPT_NO_SYNC]) + .overrides_with_all([OPT_SYNC, OPT_NO_SYNC]) .help("do not invoke sync before getting usage info (default)") .action(ArgAction::SetTrue), ) @@ -577,9 +577,9 @@ pub fn uu_app() -> Command { .require_equals(true) .use_value_delimiter(true) .value_parser(OUTPUT_FIELD_LIST) - .default_missing_values(&OUTPUT_FIELD_LIST) - .default_values(&["source", "size", "used", "avail", "pcent", "target"]) - .conflicts_with_all(&[OPT_INODES, OPT_PORTABILITY, OPT_PRINT_TYPE]) + .default_missing_values(OUTPUT_FIELD_LIST) + .default_values(["source", "size", "used", "avail", "pcent", "target"]) + .conflicts_with_all([OPT_INODES, OPT_PORTABILITY, OPT_PRINT_TYPE]) .help( "use the output format defined by FIELD_LIST, \ or print all fields if FIELD_LIST is omitted.", @@ -596,7 +596,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(OPT_SYNC) .long("sync") - .overrides_with_all(&[OPT_NO_SYNC, OPT_SYNC]) + .overrides_with_all([OPT_NO_SYNC, OPT_SYNC]) .help("invoke sync before getting usage info (non-windows only)") .action(ArgAction::SetTrue), ) diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index ebf0d46e7..65819a800 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -64,6 +64,9 @@ fn print_escaped(input: &str, mut output: impl Write) -> io::Result { let mut buffer = ['\\'; 2]; + // TODO `cargo +nightly clippy` complains that `.peek()` is never + // called on `iter`. However, `peek()` is called inside the + // `parse_code()` function that borrows `iter`. let mut iter = input.chars().peekable(); while let Some(mut c) = iter.next() { let mut start = 1; diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 2d01c9d64..87c79fe1f 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -278,8 +278,8 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { let tag = matches.get_flag("tag"); let nonames = *matches .try_get_one("no-names") - .unwrap_or(Some(&false)) - .unwrap(); + .unwrap_or(None) + .unwrap_or(&false); let status = matches.get_flag("status"); let quiet = matches.get_flag("quiet") || status; let strict = matches.get_flag("strict"); diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index a01fe94f7..32a4ad376 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -59,7 +59,7 @@ pub fn uu_app() -> Command { NUM bytes of each file\ ", ) - .overrides_with_all(&[options::BYTES_NAME, options::LINES_NAME]) + .overrides_with_all([options::BYTES_NAME, options::LINES_NAME]) .allow_hyphen_values(true), ) .arg( @@ -74,7 +74,7 @@ pub fn uu_app() -> Command { NUM lines of each file\ ", ) - .overrides_with_all(&[options::LINES_NAME, options::BYTES_NAME]) + .overrides_with_all([options::LINES_NAME, options::BYTES_NAME]) .allow_hyphen_values(true), ) .arg( @@ -83,7 +83,7 @@ pub fn uu_app() -> Command { .long("quiet") .visible_alias("silent") .help("never print headers giving file names") - .overrides_with_all(&[options::VERBOSE_NAME, options::QUIET_NAME]) + .overrides_with_all([options::VERBOSE_NAME, options::QUIET_NAME]) .action(ArgAction::SetTrue), ) .arg( @@ -91,7 +91,7 @@ pub fn uu_app() -> Command { .short('v') .long("verbose") .help("always print headers giving file names") - .overrides_with_all(&[options::QUIET_NAME, options::VERBOSE_NAME]) + .overrides_with_all([options::QUIET_NAME, options::VERBOSE_NAME]) .action(ArgAction::SetTrue), ) .arg( diff --git a/src/uu/hostid/Cargo.toml b/src/uu/hostid/Cargo.toml index 0938a1bec..81dfb68d1 100644 --- a/src/uu/hostid/Cargo.toml +++ b/src/uu/hostid/Cargo.toml @@ -16,7 +16,7 @@ path = "src/hostid.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } [[bin]] diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index b9699d99a..92950f137 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -81,7 +81,7 @@ pub fn uu_app() -> Command { Arg::new(OPT_DOMAIN) .short('d') .long("domain") - .overrides_with_all(&[OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) + .overrides_with_all([OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) .help("Display the name of the DNS domain if possible") .action(ArgAction::SetTrue), ) @@ -89,7 +89,7 @@ pub fn uu_app() -> Command { Arg::new(OPT_IP_ADDRESS) .short('i') .long("ip-address") - .overrides_with_all(&[OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) + .overrides_with_all([OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) .help("Display the network address(es) of the host") .action(ArgAction::SetTrue), ) @@ -97,7 +97,7 @@ pub fn uu_app() -> Command { Arg::new(OPT_FQDN) .short('f') .long("fqdn") - .overrides_with_all(&[OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) + .overrides_with_all([OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) .help("Display the FQDN (Fully Qualified Domain Name) (default)") .action(ArgAction::SetTrue), ) @@ -105,7 +105,7 @@ pub fn uu_app() -> Command { Arg::new(OPT_SHORT) .short('s') .long("short") - .overrides_with_all(&[OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) + .overrides_with_all([OPT_DOMAIN, OPT_IP_ADDRESS, OPT_FQDN, OPT_SHORT]) .help("Display the short hostname (the portion before the first dot) if possible") .action(ArgAction::SetTrue), ) diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 720339545..61a975978 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -348,7 +348,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::OPT_AUDIT) .short('A') - .conflicts_with_all(&[ + .conflicts_with_all([ options::OPT_GROUP, options::OPT_EFFECTIVE_USER, options::OPT_HUMAN_READABLE, @@ -382,7 +382,7 @@ pub fn uu_app() -> Command { Arg::new(options::OPT_GROUPS) .short('G') .long(options::OPT_GROUPS) - .conflicts_with_all(&[ + .conflicts_with_all([ options::OPT_GROUP, options::OPT_EFFECTIVE_USER, options::OPT_CONTEXT, @@ -443,7 +443,7 @@ pub fn uu_app() -> Command { Arg::new(options::OPT_CONTEXT) .short('Z') .long(options::OPT_CONTEXT) - .conflicts_with_all(&[options::OPT_GROUP, options::OPT_EFFECTIVE_USER]) + .conflicts_with_all([options::OPT_GROUP, options::OPT_EFFECTIVE_USER]) .help(CONTEXT_HELP_TEXT) .action(ArgAction::SetTrue), ) diff --git a/src/uu/logname/Cargo.toml b/src/uu/logname/Cargo.toml index e688346ce..72c264fe6 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.135" +libc = "0.2.137" clap = { version = "4.0", features = ["wrap_help", "cargo"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index a30cda01d..054ff9127 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -981,7 +981,7 @@ pub fn uu_app() -> Command { ]) .hide_possible_values(true) .require_equals(true) - .overrides_with_all(&[ + .overrides_with_all([ options::FORMAT, options::format::COLUMNS, options::format::LONG, @@ -993,7 +993,7 @@ pub fn uu_app() -> Command { Arg::new(options::format::COLUMNS) .short('C') .help("Display the files in columns.") - .overrides_with_all(&[ + .overrides_with_all([ options::FORMAT, options::format::COLUMNS, options::format::LONG, @@ -1007,7 +1007,7 @@ pub fn uu_app() -> Command { .short('l') .long(options::format::LONG) .help("Display detailed information.") - .overrides_with_all(&[ + .overrides_with_all([ options::FORMAT, options::format::COLUMNS, options::format::LONG, @@ -1020,7 +1020,7 @@ pub fn uu_app() -> Command { Arg::new(options::format::ACROSS) .short('x') .help("List entries in rows instead of in columns.") - .overrides_with_all(&[ + .overrides_with_all([ options::FORMAT, options::format::COLUMNS, options::format::LONG, @@ -1042,7 +1042,7 @@ pub fn uu_app() -> Command { Arg::new(options::format::COMMAS) .short('m') .help("List entries separated by commas.") - .overrides_with_all(&[ + .overrides_with_all([ options::FORMAT, options::format::COLUMNS, options::format::LONG, @@ -1114,7 +1114,7 @@ pub fn uu_app() -> Command { "c", "escape", ]) - .overrides_with_all(&[ + .overrides_with_all([ options::QUOTING_STYLE, options::quoting::LITERAL, options::quoting::ESCAPE, @@ -1126,7 +1126,7 @@ pub fn uu_app() -> Command { .short('N') .long(options::quoting::LITERAL) .help("Use literal quoting style. Equivalent to `--quoting-style=literal`") - .overrides_with_all(&[ + .overrides_with_all([ options::QUOTING_STYLE, options::quoting::LITERAL, options::quoting::ESCAPE, @@ -1139,7 +1139,7 @@ pub fn uu_app() -> Command { .short('b') .long(options::quoting::ESCAPE) .help("Use escape quoting style. Equivalent to `--quoting-style=escape`") - .overrides_with_all(&[ + .overrides_with_all([ options::QUOTING_STYLE, options::quoting::LITERAL, options::quoting::ESCAPE, @@ -1152,7 +1152,7 @@ pub fn uu_app() -> Command { .short('Q') .long(options::quoting::C) .help("Use C quoting style. Equivalent to `--quoting-style=c`") - .overrides_with_all(&[ + .overrides_with_all([ options::QUOTING_STYLE, options::quoting::LITERAL, options::quoting::ESCAPE, @@ -1166,14 +1166,14 @@ pub fn uu_app() -> Command { .short('q') .long(options::HIDE_CONTROL_CHARS) .help("Replace control characters with '?' if they are not escaped.") - .overrides_with_all(&[options::HIDE_CONTROL_CHARS, options::SHOW_CONTROL_CHARS]) + .overrides_with_all([options::HIDE_CONTROL_CHARS, options::SHOW_CONTROL_CHARS]) .action(ArgAction::SetTrue), ) .arg( Arg::new(options::SHOW_CONTROL_CHARS) .long(options::SHOW_CONTROL_CHARS) .help("Show control characters 'as is' if they are not escaped.") - .overrides_with_all(&[options::HIDE_CONTROL_CHARS, options::SHOW_CONTROL_CHARS]) + .overrides_with_all([options::HIDE_CONTROL_CHARS, options::SHOW_CONTROL_CHARS]) .action(ArgAction::SetTrue), ) // Time arguments @@ -1192,7 +1192,7 @@ pub fn uu_app() -> Command { ]) .hide_possible_values(true) .require_equals(true) - .overrides_with_all(&[options::TIME, options::time::ACCESS, options::time::CHANGE]), + .overrides_with_all([options::TIME, options::time::ACCESS, options::time::CHANGE]), ) .arg( Arg::new(options::time::CHANGE) @@ -1203,7 +1203,7 @@ pub fn uu_app() -> Command { time. When explicitly sorting by time (--sort=time or -t) or when not \ using a long listing format, sort according to the status change time.", ) - .overrides_with_all(&[options::TIME, options::time::ACCESS, options::time::CHANGE]) + .overrides_with_all([options::TIME, options::time::ACCESS, options::time::CHANGE]) .action(ArgAction::SetTrue), ) .arg( @@ -1215,7 +1215,7 @@ pub fn uu_app() -> Command { sorting by time (--sort=time or -t) or when not using a long listing \ format, sort according to the access time.", ) - .overrides_with_all(&[options::TIME, options::time::ACCESS, options::time::CHANGE]) + .overrides_with_all([options::TIME, options::time::ACCESS, options::time::CHANGE]) .action(ArgAction::SetTrue), ) // Hide and ignore @@ -1251,7 +1251,7 @@ pub fn uu_app() -> Command { .value_name("field") .value_parser(["name", "none", "time", "size", "version", "extension"]) .require_equals(true) - .overrides_with_all(&[ + .overrides_with_all([ options::SORT, options::sort::SIZE, options::sort::TIME, @@ -1264,7 +1264,7 @@ pub fn uu_app() -> Command { Arg::new(options::sort::SIZE) .short('S') .help("Sort by file size, largest first.") - .overrides_with_all(&[ + .overrides_with_all([ options::SORT, options::sort::SIZE, options::sort::TIME, @@ -1278,7 +1278,7 @@ pub fn uu_app() -> Command { Arg::new(options::sort::TIME) .short('t') .help("Sort by modification time (the 'mtime' in the inode), newest first.") - .overrides_with_all(&[ + .overrides_with_all([ options::SORT, options::sort::SIZE, options::sort::TIME, @@ -1292,7 +1292,7 @@ pub fn uu_app() -> Command { Arg::new(options::sort::VERSION) .short('v') .help("Natural sort of (version) numbers in the filenames.") - .overrides_with_all(&[ + .overrides_with_all([ options::SORT, options::sort::SIZE, options::sort::TIME, @@ -1306,7 +1306,7 @@ pub fn uu_app() -> Command { Arg::new(options::sort::EXTENSION) .short('X') .help("Sort alphabetically by entry extension.") - .overrides_with_all(&[ + .overrides_with_all([ options::SORT, options::sort::SIZE, options::sort::TIME, @@ -1324,7 +1324,7 @@ pub fn uu_app() -> Command { directory. This is especially useful when listing very large directories, \ since not doing any sorting can be noticeably faster.", ) - .overrides_with_all(&[ + .overrides_with_all([ options::SORT, options::sort::SIZE, options::sort::TIME, @@ -1343,7 +1343,7 @@ pub fn uu_app() -> Command { "When showing file information for a symbolic link, show information for the \ file the link references rather than the link itself.", ) - .overrides_with_all(&[ + .overrides_with_all([ options::dereference::ALL, options::dereference::DIR_ARGS, options::dereference::ARGS, @@ -1357,7 +1357,7 @@ pub fn uu_app() -> Command { "Do not dereference symlinks except when they link to directories and are \ given as command line arguments.", ) - .overrides_with_all(&[ + .overrides_with_all([ options::dereference::ALL, options::dereference::DIR_ARGS, options::dereference::ARGS, @@ -1369,7 +1369,7 @@ pub fn uu_app() -> Command { .short('H') .long(options::dereference::ARGS) .help("Do not dereference symlinks except when given as command line arguments.") - .overrides_with_all(&[ + .overrides_with_all([ options::dereference::ALL, options::dereference::DIR_ARGS, options::dereference::ARGS, @@ -1509,7 +1509,7 @@ pub fn uu_app() -> Command { none (default), slash (-p), file-type (--file-type), classify (-F)", ) .value_parser(["none", "slash", "file-type", "classify"]) - .overrides_with_all(&[ + .overrides_with_all([ options::indicator_style::FILE_TYPE, options::indicator_style::SLASH, options::indicator_style::CLASSIFY, @@ -1545,7 +1545,7 @@ pub fn uu_app() -> Command { .default_missing_value("always") .require_equals(true) .num_args(0..=1) - .overrides_with_all(&[ + .overrides_with_all([ options::indicator_style::FILE_TYPE, options::indicator_style::SLASH, options::indicator_style::CLASSIFY, @@ -1556,7 +1556,7 @@ pub fn uu_app() -> Command { Arg::new(options::indicator_style::FILE_TYPE) .long(options::indicator_style::FILE_TYPE) .help("Same as --classify, but do not append '*'") - .overrides_with_all(&[ + .overrides_with_all([ options::indicator_style::FILE_TYPE, options::indicator_style::SLASH, options::indicator_style::CLASSIFY, @@ -1568,7 +1568,7 @@ pub fn uu_app() -> Command { Arg::new(options::indicator_style::SLASH) .short('p') .help("Append / indicator to directories.") - .overrides_with_all(&[ + .overrides_with_all([ options::indicator_style::FILE_TYPE, options::indicator_style::SLASH, options::indicator_style::CLASSIFY, @@ -1584,7 +1584,7 @@ pub fn uu_app() -> Command { .value_name("TIME_STYLE") .env("TIME_STYLE") .value_parser(NonEmptyStringValueParser::new()) - .overrides_with_all(&[options::TIME_STYLE]), + .overrides_with_all([options::TIME_STYLE]), ) .arg( Arg::new(options::FULL_TIME) diff --git a/src/uu/mkfifo/Cargo.toml b/src/uu/mkfifo/Cargo.toml index f932697ff..c0c319cff 100644 --- a/src/uu/mkfifo/Cargo.toml +++ b/src/uu/mkfifo/Cargo.toml @@ -16,7 +16,7 @@ path = "src/mkfifo.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } [[bin]] diff --git a/src/uu/mknod/Cargo.toml b/src/uu/mknod/Cargo.toml index 7e21983ff..03a09279f 100644 --- a/src/uu/mknod/Cargo.toml +++ b/src/uu/mknod/Cargo.toml @@ -17,7 +17,7 @@ path = "src/mknod.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "^0.2.135" +libc = "^0.2.137" uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["mode"] } [[bin]] diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index ded46539f..4697fac4a 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -371,6 +371,12 @@ fn rename(from: &Path, to: &Path, b: &Behavior) -> io::Result<()> { let mut backup_path = None; if to.exists() { + if b.update && b.overwrite == OverwriteMode::Interactive { + // `mv -i --update old new` when `new` exists doesn't move anything + // and exit with 0 + return Ok(()); + } + match b.overwrite { OverwriteMode::NoClobber => return Ok(()), OverwriteMode::Interactive => { diff --git a/src/uu/nice/Cargo.toml b/src/uu/nice/Cargo.toml index c062d4db3..f9ea3c38c 100644 --- a/src/uu/nice/Cargo.toml +++ b/src/uu/nice/Cargo.toml @@ -16,7 +16,7 @@ path = "src/nice.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" nix = { version = "0.25", default-features = false } uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } diff --git a/src/uu/nohup/Cargo.toml b/src/uu/nohup/Cargo.toml index 5603d96c0..883c90b9d 100644 --- a/src/uu/nohup/Cargo.toml +++ b/src/uu/nohup/Cargo.toml @@ -16,7 +16,7 @@ path = "src/nohup.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" atty = "0.2" uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["fs"] } diff --git a/src/uu/nproc/Cargo.toml b/src/uu/nproc/Cargo.toml index e830b06a2..057062a73 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.135" +libc = "0.2.137" num_cpus = "1.10" clap = { version = "4.0", features = ["wrap_help", "cargo"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["fs"] } diff --git a/src/uu/numfmt/src/format.rs b/src/uu/numfmt/src/format.rs index 3550f3bc2..b97993f21 100644 --- a/src/uu/numfmt/src/format.rs +++ b/src/uu/numfmt/src/format.rs @@ -161,7 +161,11 @@ fn transform_from(s: &str, opts: &TransformOptions) -> Result { remove_suffix(i, suffix, &opts.from).map(|n| { // GNU numfmt doesn't round values if no --from argument is provided by the user if opts.from == Unit::None { - n + if n == -0.0 { + 0.0 + } else { + n + } } else if n < 0.0 { -n.abs().ceil() } else { @@ -268,14 +272,13 @@ fn transform_to( let (i2, s) = consider_suffix(s, &opts.to, round_method, precision)?; let i2 = i2 / (opts.to_unit as f64); Ok(match s { - None if precision > 0 => { + None => { format!( "{:.precision$}", round_with_precision(i2, round_method, precision), precision = precision ) } - None => format!("{}", i2), Some(s) if precision > 0 => { format!( "{:.precision$}{}", diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index ba76b7f77..f6a1f2739 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -275,6 +275,7 @@ pub fn uu_app() -> Command { .long(options::FIELD) .help("replace the numbers in these input fields; see FIELDS below") .value_name("FIELDS") + .allow_hyphen_values(true) .default_value(options::FIELD_DEFAULT), ) .arg( diff --git a/src/uu/pathchk/Cargo.toml b/src/uu/pathchk/Cargo.toml index b25450b89..9c77eff09 100644 --- a/src/uu/pathchk/Cargo.toml +++ b/src/uu/pathchk/Cargo.toml @@ -16,7 +16,7 @@ path = "src/pathchk.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } [[bin]] diff --git a/src/uu/pwd/src/pwd.rs b/src/uu/pwd/src/pwd.rs index 732df19f6..b1e2b30ff 100644 --- a/src/uu/pwd/src/pwd.rs +++ b/src/uu/pwd/src/pwd.rs @@ -126,7 +126,10 @@ fn logical_path() -> io::Result { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; - let cwd = if matches.get_flag(OPT_LOGICAL) { + // if POSIXLY_CORRECT is set, we want to a logical resolution. + // This produces a different output when doing mkdir -p a/b && ln -s a/b c && cd c && pwd + // We should get c in this case instead of a/b at the end of the path + let cwd = if matches.get_flag(OPT_LOGICAL) || env::var("POSIXLY_CORRECT").is_ok() { logical_path() } else { physical_path() diff --git a/src/uu/realpath/src/realpath.rs b/src/uu/realpath/src/realpath.rs index b5f9ebd11..5ca5d687b 100644 --- a/src/uu/realpath/src/realpath.rs +++ b/src/uu/realpath/src/realpath.rs @@ -130,7 +130,7 @@ pub fn uu_app() -> Command { Arg::new(OPT_PHYSICAL) .short('P') .long(OPT_PHYSICAL) - .overrides_with_all(&[OPT_STRIP, OPT_LOGICAL]) + .overrides_with_all([OPT_STRIP, OPT_LOGICAL]) .help("resolve symlinks as encountered (default)") .action(ArgAction::SetTrue), ) diff --git a/src/uu/rmdir/Cargo.toml b/src/uu/rmdir/Cargo.toml index a96a2cec1..5616742a5 100644 --- a/src/uu/rmdir/Cargo.toml +++ b/src/uu/rmdir/Cargo.toml @@ -17,7 +17,7 @@ path = "src/rmdir.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["fs"] } -libc = "0.2.135" +libc = "0.2.137" [[bin]] name = "rmdir" diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index c1bb750be..9d23034ad 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1336,7 +1336,7 @@ pub fn uu_app() -> Command { "version", "random", ]) - .conflicts_with_all(&options::modes::ALL_SORT_MODES), + .conflicts_with_all(options::modes::ALL_SORT_MODES), ) .arg(make_sort_mode_arg( options::modes::HUMAN_NUMERIC, @@ -1373,7 +1373,7 @@ pub fn uu_app() -> Command { .short('d') .long(options::DICTIONARY_ORDER) .help("consider only blanks and alphanumeric characters") - .conflicts_with_all(&[ + .conflicts_with_all([ options::modes::NUMERIC, options::modes::GENERAL_NUMERIC, options::modes::HUMAN_NUMERIC, @@ -1425,7 +1425,7 @@ pub fn uu_app() -> Command { .short('i') .long(options::IGNORE_NONPRINTING) .help("ignore nonprinting characters") - .conflicts_with_all(&[ + .conflicts_with_all([ options::modes::NUMERIC, options::modes::GENERAL_NUMERIC, options::modes::HUMAN_NUMERIC, diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 44447e9b7..365dd279b 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -1221,6 +1221,47 @@ where Ok(()) } +fn split_into_n_chunks_by_line_round_robin( + settings: &Settings, + reader: &mut R, + num_chunks: u64, +) -> UResult<()> +where + R: BufRead, +{ + // This object is responsible for creating the filename for each chunk. + let mut filename_iterator = FilenameIterator::new( + &settings.prefix, + &settings.additional_suffix, + settings.suffix_length, + settings.suffix_type, + settings.suffix_start, + )?; + + // Create one writer for each chunk. This will create each + // of the underlying files (if not in `--filter` mode). + let mut writers = vec![]; + for _ in 0..num_chunks { + let filename = filename_iterator + .next() + .ok_or_else(|| USimpleError::new(1, "output file suffixes exhausted"))?; + let writer = settings.instantiate_current_writer(filename.as_str())?; + writers.push(writer); + } + + let num_chunks: usize = num_chunks.try_into().unwrap(); + for (i, line_result) in reader.lines().enumerate() { + let line = line_result.unwrap(); + let maybe_writer = writers.get_mut(i % num_chunks); + let writer = maybe_writer.unwrap(); + let bytes = line.as_bytes(); + writer.write_all(bytes)?; + writer.write_all(b"\n")?; + } + + Ok(()) +} + fn split(settings: &Settings) -> UResult<()> { let mut reader = BufReader::new(if settings.input == "-" { Box::new(stdin()) as Box @@ -1247,6 +1288,9 @@ fn split(settings: &Settings) -> UResult<()> { let chunk_number = chunk_number - 1; kth_chunk_by_line(settings, &mut reader, chunk_number, num_chunks) } + Strategy::Number(NumberType::RoundRobin(num_chunks)) => { + split_into_n_chunks_by_line_round_robin(settings, &mut reader, num_chunks) + } Strategy::Number(_) => Err(USimpleError::new(1, "-n mode not yet fully implemented")), Strategy::Lines(chunk_size) => { let mut writer = LineChunkWriter::new(chunk_size, settings)?; diff --git a/src/uu/sync/Cargo.toml b/src/uu/sync/Cargo.toml index dc5754e43..3558868a5 100644 --- a/src/uu/sync/Cargo.toml +++ b/src/uu/sync/Cargo.toml @@ -16,7 +16,7 @@ path = "src/sync.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["wide"] } [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] diff --git a/src/uu/tail/Cargo.toml b/src/uu/tail/Cargo.toml index a912bf352..4c2552d0c 100644 --- a/src/uu/tail/Cargo.toml +++ b/src/uu/tail/Cargo.toml @@ -17,7 +17,7 @@ path = "src/tail.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" memchr = "2.5.0" notify = { version = "=5.0.0", features=["macos_kqueue"]} uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["ringbuffer", "lines"] } diff --git a/src/uu/tail/src/args.rs b/src/uu/tail/src/args.rs index 4c3f0c56d..6bc9baf0b 100644 --- a/src/uu/tail/src/args.rs +++ b/src/uu/tail/src/args.rs @@ -334,7 +334,7 @@ pub fn uu_app() -> Command { .short('c') .long(options::BYTES) .allow_hyphen_values(true) - .overrides_with_all(&[options::BYTES, options::LINES]) + .overrides_with_all([options::BYTES, options::LINES]) .help("Number of bytes to print"), ) .arg( @@ -352,7 +352,7 @@ pub fn uu_app() -> Command { .short('n') .long(options::LINES) .allow_hyphen_values(true) - .overrides_with_all(&[options::BYTES, options::LINES]) + .overrides_with_all([options::BYTES, options::LINES]) .help("Number of lines to print"), ) .arg( @@ -366,7 +366,7 @@ pub fn uu_app() -> Command { .short('q') .long(options::verbosity::QUIET) .visible_alias("silent") - .overrides_with_all(&[options::verbosity::QUIET, options::verbosity::VERBOSE]) + .overrides_with_all([options::verbosity::QUIET, options::verbosity::VERBOSE]) .help("Never output headers giving file names") .action(ArgAction::SetTrue), ) @@ -392,7 +392,7 @@ pub fn uu_app() -> Command { Arg::new(options::verbosity::VERBOSE) .short('v') .long(options::verbosity::VERBOSE) - .overrides_with_all(&[options::verbosity::QUIET, options::verbosity::VERBOSE]) + .overrides_with_all([options::verbosity::QUIET, options::verbosity::VERBOSE]) .help("Always output headers giving file names") .action(ArgAction::SetTrue), ) @@ -421,7 +421,7 @@ pub fn uu_app() -> Command { Arg::new(options::FOLLOW_RETRY) .short('F') .help("Same as --follow=name --retry") - .overrides_with_all(&[options::RETRY, options::FOLLOW]) + .overrides_with_all([options::RETRY, options::FOLLOW]) .action(ArgAction::SetTrue), ) .arg( diff --git a/src/uu/tee/Cargo.toml b/src/uu/tee/Cargo.toml index 311e09875..b9c6a36a9 100644 --- a/src/uu/tee/Cargo.toml +++ b/src/uu/tee/Cargo.toml @@ -16,7 +16,7 @@ path = "src/tee.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" 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.16", package="uucore", path="../../uucore", features=["libc"] } diff --git a/src/uu/test/Cargo.toml b/src/uu/test/Cargo.toml index 28b7362b1..f1ae083e0 100644 --- a/src/uu/test/Cargo.toml +++ b/src/uu/test/Cargo.toml @@ -16,7 +16,7 @@ path = "src/test.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } [target.'cfg(target_os = "redox")'.dependencies] diff --git a/src/uu/test/src/test.rs b/src/uu/test/src/test.rs index aaeb351e5..bc274bc8b 100644 --- a/src/uu/test/src/test.rs +++ b/src/uu/test/src/test.rs @@ -452,18 +452,18 @@ mod tests { fn test_integer_op() { let a = OsStr::new("18446744073709551616"); let b = OsStr::new("0"); - assert_eq!(integers(a, b, OsStr::new("-lt")).unwrap(), false); + assert!(!integers(a, b, OsStr::new("-lt")).unwrap()); let a = OsStr::new("18446744073709551616"); let b = OsStr::new("0"); - assert_eq!(integers(a, b, OsStr::new("-gt")).unwrap(), true); + assert!(integers(a, b, OsStr::new("-gt")).unwrap()); let a = OsStr::new("-1"); let b = OsStr::new("0"); - assert_eq!(integers(a, b, OsStr::new("-lt")).unwrap(), true); + assert!(integers(a, b, OsStr::new("-lt")).unwrap()); let a = OsStr::new("42"); let b = OsStr::new("42"); - assert_eq!(integers(a, b, OsStr::new("-eq")).unwrap(), true); + assert!(integers(a, b, OsStr::new("-eq")).unwrap()); let a = OsStr::new("42"); let b = OsStr::new("42"); - assert_eq!(integers(a, b, OsStr::new("-ne")).unwrap(), false); + assert!(!integers(a, b, OsStr::new("-ne")).unwrap()); } } diff --git a/src/uu/timeout/Cargo.toml b/src/uu/timeout/Cargo.toml index 77adcfe57..6c42553a9 100644 --- a/src/uu/timeout/Cargo.toml +++ b/src/uu/timeout/Cargo.toml @@ -16,7 +16,7 @@ path = "src/timeout.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" nix = { version = "0.25", default-features = false, features = ["signal"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["process", "signals"] } diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index f397d2eaf..39f328d87 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -254,7 +254,7 @@ pub fn uu_app() -> Command { .value_parser(ValueParser::os_string()) .value_hint(clap::ValueHint::AnyPath), ) - .group(ArgGroup::new(options::SOURCES).args(&[ + .group(ArgGroup::new(options::SOURCES).args([ options::sources::CURRENT, options::sources::DATE, options::sources::REFERENCE, diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 45f5c05f2..a66393acb 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -336,7 +336,7 @@ pub fn uu_app() -> Command { .num_args(0..=1) .default_missing_value("separate") .require_equals(true) - .conflicts_with_all(&[ + .conflicts_with_all([ options::REPEATED, options::ALL_REPEATED, options::UNIQUE, diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 4729d68ac..d41ce1e79 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -250,7 +250,7 @@ pub fn uu_app() -> Command { .long(options::MESG) .short('T') .visible_short_alias('w') - .visible_aliases(&["message", "writable"]) + .visible_aliases(["message", "writable"]) .help("add user's message status as +, - or ?") .action(ArgAction::SetTrue), ) @@ -350,7 +350,7 @@ impl Who { println!("{}", users.join(" ")); println!("# users={}", users.len()); } else { - let records = Utmpx::iter_all_records_from(f).peekable(); + let records = Utmpx::iter_all_records_from(f); if self.include_heading { self.print_heading(); diff --git a/src/uu/whoami/Cargo.toml b/src/uu/whoami/Cargo.toml index f3a277e89..4c1b5c2ab 100644 --- a/src/uu/whoami/Cargo.toml +++ b/src/uu/whoami/Cargo.toml @@ -22,7 +22,7 @@ uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=[ windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_NetworkManagement_NetManagement", "Win32_System_WindowsProgramming", "Win32_Foundation"] } [target.'cfg(unix)'.dependencies] -libc = "0.2.135" +libc = "0.2.137" [[bin]] name = "whoami" diff --git a/src/uu/yes/Cargo.toml b/src/uu/yes/Cargo.toml index 677d60a5f..1f2db513b 100644 --- a/src/uu/yes/Cargo.toml +++ b/src/uu/yes/Cargo.toml @@ -16,7 +16,7 @@ path = "src/yes.rs" [dependencies] clap = { version = "4.0", features = ["wrap_help", "cargo"] } -libc = "0.2.135" +libc = "0.2.137" uucore = { version=">=0.0.16", 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 f0527612f..fa1c1d74b 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -32,7 +32,7 @@ time = { version="0.3", optional=true, features = ["formatting", "local-offset", 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.135", optional=true } +libc = { version="0.2.137", optional=true } once_cell = "1.13.1" os_display = "0.1.3" diff --git a/tests/by-util/test_chown.rs b/tests/by-util/test_chown.rs index b54412857..716e7f48f 100644 --- a/tests/by-util/test_chown.rs +++ b/tests/by-util/test_chown.rs @@ -423,6 +423,38 @@ fn test_chown_only_user_id() { .stderr_contains("failed to change"); } +#[test] +fn test_chown_fail_id() { + // test chown 1111. file.txt + + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + + let result = scene.cmd_keepenv("id").arg("-u").run(); + if skipping_test_is_okay(&result, "id: cannot find name for group ID") { + return; + } + let user_id = String::from(result.stdout_str().trim()); + assert!(!user_id.is_empty()); + + let file1 = "test_chown_file1"; + at.touch(file1); + + scene + .ucmd() + .arg(format!("{}:", user_id)) + .arg(file1) + .fails() + .stderr_contains("invalid spec"); + + scene + .ucmd() + .arg(format!("{}.", user_id)) + .arg(file1) + .fails() + .stderr_contains("invalid spec"); +} + /// Test for setting the owner to a user ID for a user that does not exist. /// /// For example: @@ -708,7 +740,7 @@ fn test_chown_file_notexisting() { .fails(); // TODO: uncomment once "failed to change ownership of '{}' to {}" added to stdout - // result.stderr_contains(&"retained as"); + // result.stderr_contains("retained as"); // TODO: uncomment once message changed from "cannot dereference" to "cannot access" - // result.stderr_contains(&"cannot access 'not_existing': No such file or directory"); + // result.stderr_contains("cannot access 'not_existing': No such file or directory"); } diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 8860a57a5..5a97db0bd 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -216,16 +216,31 @@ fn test_cp_target_directory_is_file() { } #[test] -fn test_cp_arg_interactive() { +fn test_cp_arg_update_interactive() { new_ucmd!() .arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE) .arg("-i") + .arg("--update") + .succeeds() + .no_stdout() + .no_stderr(); +} + +#[test] +fn test_cp_arg_interactive() { + let (at, mut ucmd) = at_and_ucmd!(); + at.touch("a"); + at.touch("b"); + // TODO The prompt in GNU cp is different, and it doesn't have the + // response either. + // + // See . + ucmd.args(&["-i", "a", "b"]) .pipe_in("N\n") .succeeds() .no_stdout() - .stderr_contains(format!("overwrite '{}'?", TEST_HOW_ARE_YOU_SOURCE)) - .stderr_contains("Not overwriting"); + .stderr_is("cp: overwrite 'b'? [y/N]: cp: Not overwriting 'b' at user request\n"); } #[test] @@ -1996,6 +2011,19 @@ fn test_copy_same_symlink_no_dereference_dangling() { ucmd.args(&["-d", "a", "b"]).succeeds(); } +#[cfg(not(windows))] +#[test] +fn test_cp_parents_2_dirs() { + let (at, mut ucmd) = at_and_ucmd!(); + at.mkdir_all("a/b/c"); + at.mkdir("d"); + ucmd.args(&["-a", "--parents", "a/b/c", "d"]) + .succeeds() + .no_stderr() + .no_stdout(); + assert!(at.dir_exists("d/a/b/c")); +} + #[test] #[ignore = "issue #3332"] fn test_cp_parents_2() { diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 310c84290..0b3b3f788 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -1863,7 +1863,7 @@ fn test_ls_recursive() { #[cfg(not(windows))] result.stdout_contains("a/b:\nb"); #[cfg(windows)] - result.stdout_contains(&"a\\b:\nb"); + result.stdout_contains("a\\b:\nb"); } #[test] @@ -2093,13 +2093,13 @@ fn test_ls_indicator_style() { .ucmd() .arg(format!("--indicator-style={}", opt)) .succeeds() - .stdout_contains(&"/"); + .stdout_contains("/"); } // Same test as above, but with the alternate flags. let options = vec!["--classify", "--file-type", "-p"]; for opt in options { - scene.ucmd().arg(opt).succeeds().stdout_contains(&"/"); + scene.ucmd().arg(opt).succeeds().stdout_contains("/"); } // Classify and File-Type all contain indicators for pipes and links. @@ -2110,7 +2110,7 @@ fn test_ls_indicator_style() { .ucmd() .arg(format!("--indicator-style={}", opt)) .succeeds() - .stdout_contains(&"@"); + .stdout_contains("@"); } } @@ -3195,7 +3195,7 @@ fn test_ls_context_format() { ] { let format = format!("--format={}", word); ts.ucmd() - .args(&[&"-Z", &format.as_str(), &"/"]) + .args(&["-Z", format.as_str(), "/"]) .succeeds() .stdout_only( unwrap_or_return!(expected_result(&ts, &["-Z", format.as_str(), "/"])).stdout_str(), diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 200053ba6..9dd06c9f1 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -184,6 +184,25 @@ fn test_mv_interactive() { assert!(at.file_exists(file_b)); } +#[test] +fn test_mv_arg_update_interactive() { + let (at, mut ucmd) = at_and_ucmd!(); + + let file_a = "test_mv_replace_file_a"; + let file_b = "test_mv_replace_file_b"; + + at.touch(file_a); + at.touch(file_b); + + ucmd.arg(file_a) + .arg(file_b) + .arg("-i") + .arg("--update") + .succeeds() + .no_stdout() + .no_stderr(); +} + #[test] fn test_mv_no_clobber() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index b12ea2d50..49de861fb 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -184,6 +184,11 @@ fn test_negative() { .stdout_is("-1.0Ki\n-1.2Mi\n-103Mi\n"); } +#[test] +fn test_negative_zero() { + new_ucmd!().pipe_in("-0\n-0.0").run().stdout_is("0\n0.0\n"); +} + #[test] fn test_no_op() { new_ucmd!() @@ -370,6 +375,14 @@ fn test_format_selected_fields() { .stdout_only("1000 2K 3000 4000 5K 6K\n"); } +#[test] +fn test_format_implied_range_and_field() { + new_ucmd!() + .args(&["--from=auto", "--field", "-2,4", "1K 2K 3K 4K 5K 6K"]) + .succeeds() + .stdout_only("1000 2000 3K 4000 5K 6K\n"); +} + #[test] fn test_should_succeed_if_selected_field_out_of_range() { new_ucmd!() @@ -525,7 +538,7 @@ fn test_round() { new_ucmd!() .args(&[ "--to=si", - &format!("--round={}", method), + &format!("--round={method}"), "--", "9001", "-9001", @@ -537,6 +550,32 @@ fn test_round() { } } +#[test] +fn test_round_with_to_unit() { + for (method, exp) in [ + ("from-zero", ["6", "-6", "5.9", "-5.9", "5.86", "-5.86"]), + ("towards-zero", ["5", "-5", "5.8", "-5.8", "5.85", "-5.85"]), + ("up", ["6", "-5", "5.9", "-5.8", "5.86", "-5.85"]), + ("down", ["5", "-6", "5.8", "-5.9", "5.85", "-5.86"]), + ("nearest", ["6", "-6", "5.9", "-5.9", "5.86", "-5.86"]), + ] { + new_ucmd!() + .args(&[ + "--to-unit=1024", + &format!("--round={method}"), + "--", + "6000", + "-6000", + "6000.0", + "-6000.0", + "6000.00", + "-6000.00", + ]) + .succeeds() + .stdout_only(exp.join("\n") + "\n"); + } +} + #[test] fn test_suffix_is_added_if_not_supplied() { new_ucmd!() diff --git a/tests/by-util/test_pwd.rs b/tests/by-util/test_pwd.rs index 0ae63c895..0ae0cc909 100644 --- a/tests/by-util/test_pwd.rs +++ b/tests/by-util/test_pwd.rs @@ -90,6 +90,35 @@ fn test_symlinked_default() { env.ucmd.succeeds().stdout_is(env.subdir + "\n"); } +#[test] +fn test_symlinked_default_posix() { + let mut env = symlinked_env(); + env.ucmd + .env("POSIXLY_CORRECT", "1") + .succeeds() + .stdout_is(env.symdir.clone() + "\n"); +} + +#[test] +fn test_symlinked_default_posix_l() { + let mut env = symlinked_env(); + env.ucmd + .env("POSIXLY_CORRECT", "1") + .arg("-L") + .succeeds() + .stdout_is(env.symdir + "\n"); +} + +#[test] +fn test_symlinked_default_posix_p() { + let mut env = symlinked_env(); + env.ucmd + .env("POSIXLY_CORRECT", "1") + .arg("-P") + .succeeds() + .stdout_is(env.symdir + "\n"); +} + #[cfg(not(windows))] pub mod untrustworthy_pwd_var { use std::path::Path; diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 7d7bb3929..85f3e7eea 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -743,3 +743,19 @@ fn test_hex_suffix() { assert_eq!(at.read("x0b"), "c"); assert_eq!(at.read("x0c"), ""); } + +#[test] +fn test_round_robin() { + let (at, mut ucmd) = at_and_ucmd!(); + + let file_read = |f| { + let mut s = String::new(); + at.open(f).read_to_string(&mut s).unwrap(); + s + }; + + ucmd.args(&["-n", "r/2", "fivelines.txt"]).succeeds(); + + assert_eq!(file_read("xaa"), "1\n3\n5\n"); + assert_eq!(file_read("xab"), "2\n4\n"); +} diff --git a/tests/common/random.rs b/tests/common/random.rs index 0e422572f..29f3d2775 100644 --- a/tests/common/random.rs +++ b/tests/common/random.rs @@ -58,11 +58,11 @@ impl Distribution for AlphanumericNewline { /// use rand::distributions::Alphanumeric; /// /// // generates a 100 byte string with characters from AlphanumericNewline -/// let random_string = RandomString::generate(&AlphanumericNewline, 100); +/// let random_string = RandomString::generate(AlphanumericNewline, 100); /// assert_eq!(100, random_string.len()); /// /// // generates a 100 byte string with 10 newline characters not ending with a newline -/// let string = RandomString::generate_with_delimiter(&Alphanumeric, b'\n', 10, false, 100); +/// let string = RandomString::generate_with_delimiter(Alphanumeric, b'\n', 10, false, 100); /// assert_eq!(100, random_string.len()); /// ``` pub struct RandomString; @@ -108,7 +108,7 @@ impl RandomString { /// use crate::common::random::{AlphanumericNewline, RandomString}; /// /// // generates a 100 byte string with 10 '\0' byte characters not ending with a '\0' byte - /// let string = RandomString::generate_with_delimiter(&AlphanumericNewline, 0, 10, false, 100); + /// let string = RandomString::generate_with_delimiter(AlphanumericNewline, 0, 10, false, 100); /// assert_eq!(100, random_string.len()); /// assert_eq!( /// 10,