From 5262c043f3154175be1655f77f8520317ddcacc3 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Wed, 22 Jun 2022 19:54:37 +0300 Subject: [PATCH 1/4] uu_install: add 'removed file' message on overwriting file --- src/uu/install/src/install.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 6750560d2..bd853e26c 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -585,6 +585,9 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> { // The codes actually making use of the backup process don't seem to agree // on how best to approach the issue. (mv and ln, for example) if to.exists() { + if b.verbose { + println!("removed {}", to.quote()); + } backup_path = backup_control::get_backup_path(b.backup_mode, to, &b.suffix); if let Some(ref backup_path) = backup_path { // TODO!! From b22d2470ac3291614b7ab8a337e371bbb6a3b38b Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Wed, 22 Jun 2022 19:55:26 +0300 Subject: [PATCH 2/4] uu_install: check for permission change on -C option --- src/uu/install/src/install.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index bd853e26c..a9b03eb34 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -757,6 +757,8 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> UResult { // setuid || setgid || sticky let extra_mode: u32 = 0o7000; + // setuid || setgid || sticky || permissions + let all_modes: u32 = 0o7777; if b.specified_mode.unwrap_or(0) & extra_mode != 0 || from_meta.mode() & extra_mode != 0 @@ -764,6 +766,9 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> UResult { { return Ok(true); } + if b.mode() != to_meta.mode() & all_modes { + return Ok(true); + } if !from_meta.is_file() || !to_meta.is_file() { return Ok(true); From 61ad2c17b0c7f31a815bbae1eb00eda4d8860b09 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Wed, 22 Jun 2022 19:56:22 +0300 Subject: [PATCH 3/4] uu_install: add inconsistent args check --- src/uu/install/src/install.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index a9b03eb34..3da23e271 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -370,6 +370,17 @@ fn behavior(matches: &ArgMatches) -> UResult { let backup_mode = backup_control::determine_backup_mode(matches)?; let target_dir = matches.value_of(OPT_TARGET_DIRECTORY).map(|d| d.to_owned()); + let preserve_timestamps = matches.is_present(OPT_PRESERVE_TIMESTAMPS); + let compare = matches.is_present(OPT_COMPARE); + let strip = matches.is_present(OPT_STRIP); + if preserve_timestamps && compare { + show_error!("Options --compare and --preserve-timestamps are mutually exclusive"); + return Err(1.into()); + } + if compare && strip { + show_error!("Options --compare and --strip are mutually exclusive"); + return Err(1.into()); + } Ok(Behavior { main_function, specified_mode, @@ -378,9 +389,9 @@ fn behavior(matches: &ArgMatches) -> UResult { owner: matches.value_of(OPT_OWNER).unwrap_or("").to_string(), group: matches.value_of(OPT_GROUP).unwrap_or("").to_string(), verbose: matches.is_present(OPT_VERBOSE), - preserve_timestamps: matches.is_present(OPT_PRESERVE_TIMESTAMPS), - compare: matches.is_present(OPT_COMPARE), - strip: matches.is_present(OPT_STRIP), + preserve_timestamps, + compare, + strip, strip_program: String::from( matches .value_of(OPT_STRIP_PROGRAM) From ba136ba3fb395e047e6c1e777b365ab900bcd701 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Wed, 22 Jun 2022 21:30:59 +0300 Subject: [PATCH 4/4] tests: add tests for install to check -C option usage --- tests/by-util/test_install.rs | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index dca04ac56..53bc4c1ee 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -1206,3 +1206,44 @@ fn test_install_dir_req_verbose() { .succeeds() .stdout_contains("install: creating directory 'sub4/a'\ninstall: creating directory 'sub4/a/b'\ninstall: creating directory 'sub4/a/b/c'\n'source_file1' -> 'sub4/a/b/c/file'"); } + +#[test] +fn test_install_compare_option() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + let first = "a"; + let second = "b"; + at.touch(first); + scene + .ucmd() + .args(&["-Cv", first, second]) + .succeeds() + .stdout_contains(format!("'{}' -> '{}'", first, second)); + scene + .ucmd() + .args(&["-Cv", first, second]) + .succeeds() + .no_stdout(); + scene + .ucmd() + .args(&["-Cv", "-m0644", first, second]) + .succeeds() + .stdout_contains(format!("removed '{}'\n'{}' -> '{}'", second, first, second)); + scene + .ucmd() + .args(&["-Cv", first, second]) + .succeeds() + .stdout_contains(format!("removed '{}'\n'{}' -> '{}'", second, first, second)); + scene + .ucmd() + .args(&["-C", "--preserve-timestamps", first, second]) + .fails() + .code_is(1) + .stderr_contains("Options --compare and --preserve-timestamps are mutually exclusive"); + scene + .ucmd() + .args(&["-C", "--strip", "--strip-program=echo", first, second]) + .fails() + .code_is(1) + .stderr_contains("Options --compare and --strip are mutually exclusive"); +}