Skip to content

Commit

Permalink
install: with -t, check if we aren't passed a file
Browse files Browse the repository at this point in the history
Should pass tests/install/basic-1
  • Loading branch information
sylvestre committed Dec 20, 2023
1 parent c20f009 commit 41023fc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/uu/install/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,14 @@ fn standard(mut paths: Vec<String>, b: &Behavior) -> UResult<()> {
}
}
}
if b.target_dir.is_some() {
let p = to_create.unwrap();

if !p.exists() || !p.is_dir() {
show_error!("failed to access '{}': Not a directory", p.display());
return Err(1.into());
}
}
}

if sources.len() > 1 || is_potential_directory_path(&target) {
Expand Down
24 changes: 24 additions & 0 deletions tests/by-util/test_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,3 +1538,27 @@ fn test_install_compare_option() {
.code_is(1)
.stderr_contains("Options --compare and --strip are mutually exclusive");
}

#[test]
// Matches part of tests/install/basic-1
fn test_t_exist_dir() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

let source1 = "file";
let target_dir = "sub4/";
let target_file = "sub4/file_exists";

at.touch(source1);
at.mkdir(target_dir);
at.touch(target_file);

scene
.ucmd()
.arg("-t")
.arg(target_file)
.arg("-Dv")
.arg(source1)
.fails()
.stderr_contains("failed to access 'sub4/file_exists': Not a directory");
}

0 comments on commit 41023fc

Please sign in to comment.