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
This commit is contained in:
Julian Andres Klode
2025-07-29 12:24:31 +02:00
parent 79bbf52a21
commit 190ddd105c
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -607,7 +607,7 @@ fn standard(mut paths: Vec<String>, 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(),
);
+14
View File
@@ -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!());