diff --git a/src/uu/install/locales/en-US.ftl b/src/uu/install/locales/en-US.ftl index 5b06fb7796a..41dbeb335e6 100644 --- a/src/uu/install/locales/en-US.ftl +++ b/src/uu/install/locales/en-US.ftl @@ -54,6 +54,7 @@ install-error-failed-to-remove = Failed to remove existing file { $path }. Error # Warning messages install-warning-compare-ignored = the --compare (-C) option is ignored when you specify a mode with non-permission bits +install-warning-no-strip-with-program = WARNING: ignoring --strip-program option as -s option was not specified # Verbose output install-verbose-creating-directory = creating directory { $path } diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index cb12e181480..b872e0c749e 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -378,6 +378,24 @@ fn behavior(matches: &ArgMatches) -> UResult { let preserve_timestamps = matches.get_flag(OPT_PRESERVE_TIMESTAMPS); let compare = matches.get_flag(OPT_COMPARE); let strip = matches.get_flag(OPT_STRIP); + let strip_program = match matches.get_one::(OPT_STRIP_PROGRAM) { + Some(p) => { + if !strip + && writeln!( + std::io::stderr(), + "install: {}", + translate!("install-warning-no-strip-with-program") + ) + .is_err() + { + uucore::error::set_exit_code(1); + } + p + } + None => DEFAULT_STRIP_PROGRAM, + } + .to_string(); + if preserve_timestamps && compare { show_error!( "{}", @@ -458,11 +476,7 @@ fn behavior(matches: &ArgMatches) -> UResult { preserve_timestamps, compare, strip, - strip_program: String::from( - matches - .get_one::(OPT_STRIP_PROGRAM) - .map_or(DEFAULT_STRIP_PROGRAM, |s| s.as_str()), - ), + strip_program, create_leading: matches.get_flag(OPT_CREATE_LEADING), target_dir, no_target_dir, diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index 978a71d2b93..11dfa7a4ef2 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -795,6 +795,24 @@ fn test_install_and_strip() { assert!(!stdout.contains(STRIP_SOURCE_FILE_SYMBOL)); } +#[test] +#[cfg(not(windows))] +#[cfg(not(target_os = "android"))] // missing strip binary +// FIXME test runs in a timeout with macos-latest on x86_64 in the CI +#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))] +fn test_install_no_strip_with_program() { + TestScenario::new(util_name!()) + .ucmd() + .arg("--strip-program") + .arg("true") + .arg(strip_source_file()) + .arg(STRIP_TARGET_FILE) + .succeeds() + .stderr_only( + "install: WARNING: ignoring --strip-program option as -s option was not specified\n", + ); +} + #[test] #[cfg(not(windows))] #[cfg(not(target_os = "android"))] // missing strip binary