From 648eb9886a41de5a4deac0adf79c782ca51c2aa3 Mon Sep 17 00:00:00 2001 From: Kanishk Sachan Date: Thu, 1 Oct 2026 15:52:56 +0100 Subject: [PATCH] install: print the OS error, not its Debug form, when removing the destination fails --- src/uu/install/src/install.rs | 4 ++-- tests/by-util/test_install.rs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 5fc9b146f4..67fe1a3b40 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -803,7 +803,7 @@ fn standard(mut paths: Vec, b: &Behavior) -> UResult<()> { { show_error!( "{}", - translate!("install-error-failed-to-remove", "path" => target.quote(), "error" => format!("{e:?}")) + translate!("install-error-failed-to-remove", "path" => target.quote(), "error" => strip_errno(&e)) ); } @@ -1033,7 +1033,7 @@ fn copy_file(from: &Path, to: &Path) -> UResult<()> { } _ => show_error!( "{}", - translate!("install-error-failed-to-remove", "path" => to.quote(), "error" => format!("{e:?}")) + translate!("install-error-failed-to-remove", "path" => to.quote(), "error" => strip_errno(&e)) ), } } diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index b7cfe1beb5..f737ab6c0d 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -2703,6 +2703,26 @@ fn test_install_non_utf8_paths() { ucmd.arg("-D").arg(source_file).arg(&target_path).succeeds(); } +/// The error for a failed removal of the existing destination must be the +/// plain OS message, not the `Debug` form of the Rust error. +#[test] +fn test_install_failed_remove_existing_error_is_plain() { + // Root can always remove the file. + if geteuid().is_root() { + return; + } + + let (at, mut ucmd) = at_and_ucmd!(); + at.touch("f"); + at.mkdir("r--"); + at.set_mode("r--", 0o400); + + ucmd.args(&["-D", "f", "r--/f"]) + .fails() + .stderr_contains("Error: Permission denied") + .stderr_does_not_contain("Os {"); +} + /// A failed ownership change must not leave the setuid/setgid mode applied. #[test] fn test_install_failed_chown_does_not_leave_setuid() {