From 8674e867038a145b5393ab759ee1ebd3cad84668 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Mon, 19 May 2025 09:37:52 +0200 Subject: [PATCH] cp: fix warnings from unnecessary_debug_formatting Co-authored-by: Jeremy Smart --- src/uu/cp/src/cp.rs | 8 ++++++-- src/uu/cp/src/platform/macos.rs | 7 ++++++- tests/by-util/test_cp.rs | 15 +++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 203e7836f..06f0b7965 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1259,13 +1259,17 @@ fn parse_path_args( return Err("missing file operand".into()); } else if paths.len() == 1 && options.target_dir.is_none() { // Only one file specified - return Err(format!("missing destination file operand after {:?}", paths[0]).into()); + return Err(format!( + "missing destination file operand after {}", + paths[0].display().to_string().quote() + ) + .into()); } // Return an error if the user requested to copy more than one // file source to a file target if options.no_target_dir && options.target_dir.is_none() && paths.len() > 2 { - return Err(format!("extra operand {:?}", paths[2]).into()); + return Err(format!("extra operand {:}", paths[2].display().to_string().quote()).into()); } let target = match options.target_dir { diff --git a/src/uu/cp/src/platform/macos.rs b/src/uu/cp/src/platform/macos.rs index ee5ddca54..35879c29d 100644 --- a/src/uu/cp/src/platform/macos.rs +++ b/src/uu/cp/src/platform/macos.rs @@ -84,7 +84,12 @@ pub(crate) fn copy_on_write( // support COW). match reflink_mode { ReflinkMode::Always => { - return Err(format!("failed to clone {source:?} from {dest:?}: {error}").into()); + return Err(format!( + "failed to clone {} from {}: {error}", + source.display(), + dest.display() + ) + .into()); } _ => { copy_debug.reflink = OffloadReflinkDebug::Yes; diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 7f83be772..cb7eea5cd 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -2,13 +2,12 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. + // spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs neve ROOTDIR USERDIR procfs outfile uufs xattrs // spell-checker:ignore bdfl hlsl IRWXO IRWXG nconfined matchpathcon libselinux-devel -use uutests::at_and_ucmd; -use uutests::new_ucmd; -use uutests::path_concat; +use uucore::display::Quotable; use uutests::util::TestScenario; -use uutests::util_name; +use uutests::{at_and_ucmd, new_ucmd, path_concat, util_name}; #[cfg(not(windows))] use std::fs::set_permissions; @@ -3946,10 +3945,10 @@ fn test_cp_only_source_no_target() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; at.touch("a"); - ts.ucmd() - .arg("a") - .fails() - .stderr_contains("missing destination file operand after \"a\""); + ts.ucmd().arg("a").fails().stderr_contains(format!( + "missing destination file operand after {}", + "a".quote() + )); } #[test]