From 3214c4d604f0a3faa37da0ddc93283008988314d Mon Sep 17 00:00:00 2001 From: jenningsfan <97118281+jenningsfan@users.noreply.github.com> Date: Sat, 28 Jun 2025 08:57:55 +0100 Subject: [PATCH] install: don't error when multiple arguments of the same type are given, instead override with last one (#8033) (#8053) --- src/uu/install/src/install.rs | 1 + tests/by-util/test_install.rs | 74 +++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index db7cfb4ce..ee639de97 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -187,6 +187,7 @@ pub fn uu_app() -> Command { .about(get_message("install-about")) .override_usage(format_usage(&get_message("install-usage"))) .infer_long_args(true) + .args_override_self(true) .arg(backup_control::arguments::backup()) .arg(backup_control::arguments::backup_no_args()) .arg( diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index c402f3537..451685a25 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -447,6 +447,80 @@ fn test_install_nested_paths_copy_file() { assert!(at.file_exists(format!("{dir2}/{file1}"))); } +#[test] +fn test_multiple_mode_arguments_override_not_error() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + let dir = "source_dir"; + + let file = "source_file"; + let gid = getegid(); + let uid = geteuid(); + + at.touch(file); + at.mkdir(dir); + + scene + .ucmd() + .args(&[ + file, + &format!("{dir}/{file}"), + "--owner=invalid_owner", + "--owner", + &uid.to_string(), + ]) + .succeeds() + .no_stderr(); + + scene + .ucmd() + .args(&[ + file, + &format!("{dir}/{file}"), + "-o invalid_owner", + "-o", + &uid.to_string(), + ]) + .succeeds() + .no_stderr(); + + scene + .ucmd() + .args(&[file, &format!("{dir}/{file}"), "--mode=999", "--mode=200"]) + .succeeds() + .no_stderr(); + + scene + .ucmd() + .args(&[file, &format!("{dir}/{file}"), "-m 999", "-m 200"]) + .succeeds() + .no_stderr(); + + scene + .ucmd() + .args(&[ + file, + &format!("{dir}/{file}"), + "--group=invalid_group", + "--group", + &gid.to_string(), + ]) + .succeeds() + .no_stderr(); + + scene + .ucmd() + .args(&[ + file, + &format!("{dir}/{file}"), + "-g invalid_group", + "-g", + &gid.to_string(), + ]) + .succeeds() + .no_stderr(); +} + #[test] fn test_install_failing_omitting_directory() { let scene = TestScenario::new(util_name!());