From 190ddd105cd33f27e146b0e63cf30632161b7291 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 29 Jul 2025 12:08:32 +0200 Subject: [PATCH] install: Fix --no-target-directory with existing file install should silently override existing target files, but it inadvertently checked whether the target exists rather than for the target being a directory, hence the overwrite failed, saying it cannot overwrite the directory with non-directory. Bug-Ubuntu: https://bugs.launchpad.net/bugs/2118785 --- src/uu/install/src/install.rs | 2 +- tests/by-util/test_install.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 8d69991cf..10717c659 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -607,7 +607,7 @@ fn standard(mut paths: Vec, b: &Behavior) -> UResult<()> { return Err(InstallError::OmittingDirectory(source.clone()).into()); } - if b.no_target_dir && target.exists() { + if b.no_target_dir && target.is_dir() { return Err( InstallError::OverrideDirectoryFailed(target.clone(), source.clone()).into(), ); diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index 7af4c6baa..436e5a424 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -2082,6 +2082,20 @@ fn test_install_no_target_directory_failing_cannot_overwrite() { assert!(!at.dir_exists("dir/file")); } +#[test] +fn test_install_no_target_directory_overwrite_file() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + let file = "file"; + let dest = "dest"; + + at.touch(file); + scene.ucmd().arg("-T").arg(file).arg(dest).succeeds(); + scene.ucmd().arg("-T").arg(file).arg(dest).succeeds(); + + assert!(!at.dir_exists("dir/file")); +} + #[test] fn test_install_no_target_directory_failing_omitting_directory() { let scene = TestScenario::new(util_name!());