mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
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:
@@ -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(),
|
||||
);
|
||||
|
||||
@@ -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!());
|
||||
|
||||
Reference in New Issue
Block a user