From 332767e548a1d743f556372c1e1dd571089a29da Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sat, 22 Sep 2018 19:10:14 -0500 Subject: [PATCH 1/2] cp: add test for "`cp` always creates backup" --- tests/test_cp.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_cp.rs b/tests/test_cp.rs index d47fbb5c9..c74b47f58 100644 --- a/tests/test_cp.rs +++ b/tests/test_cp.rs @@ -31,6 +31,23 @@ fn test_cp_cp() { } +#[test] +fn test_cp_existing_target() { + let (at, mut ucmd) = at_and_ucmd!(); + let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) + .arg(TEST_EXISTING_FILE) + .run(); + + assert!(result.success); + + // Check the content of the destination file + assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n"); + + // No backup should have been created + assert!(!at.file_exists(&*format!("{}~", TEST_EXISTING_FILE))); +} + + #[test] fn test_cp_duplicate_files() { let (at, mut ucmd) = at_and_ucmd!(); From 1d64162218bca669f78cf716b885b763aa5f3532 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sat, 22 Sep 2018 18:36:01 -0500 Subject: [PATCH 2/2] cp: fix "`cp` always creates backup" --- src/cp/cp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cp/cp.rs b/src/cp/cp.rs index e19904ef1..0d5d31a95 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -579,7 +579,7 @@ impl Options { let recursive = matches.is_present(OPT_RECURSIVE) || matches.is_present(OPT_RECURSIVE_ALIAS) || matches.is_present(OPT_ARCHIVE); - let backup = matches.is_present(OPT_BACKUP) || matches.is_present(OPT_SUFFIX); + let backup = matches.is_present(OPT_BACKUP) || (matches.occurrences_of(OPT_SUFFIX) > 0); // Parse target directory options let no_target_dir = matches.is_present(OPT_NO_TARGET_DIRECTORY);