1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

bug(install) - install -d can be run on an existing directory (#1643)

GNU:
$ install -d foo
$ install -d foo

Rust:
$ install -d foo
$ install -d foo
install: cannot create directory 'foo': File exists
install: foo: File exists (os error 17)
This commit is contained in:
Sylvestre Ledru 2020-11-29 16:31:26 +01:00 committed by GitHub
parent 8ef7f394c1
commit 89f8624936
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 23 deletions

View file

@ -363,14 +363,12 @@ fn directory(paths: Vec<String>, b: Behavior) -> i32 {
for directory in paths.iter() {
let path = Path::new(directory);
if path.exists() {
show_info!("cannot create directory '{}': File exists", path.display());
all_successful = false;
}
if let Err(e) = fs::create_dir(directory) {
show_info!("{}: {}", path.display(), e.to_string());
all_successful = false;
// if the path already exist, don't try to create it again
if !path.exists() {
if let Err(e) = fs::create_dir(directory) {
show_info!("{}: {}", path.display(), e.to_string());
all_successful = false;
}
}
if mode::chmod(&path, b.mode()).is_err() {

View file

@ -31,6 +31,18 @@ fn test_install_basic() {
assert!(at.file_exists(&format!("{}/{}", dir, file2)));
}
#[test]
fn test_install_twice_dir() {
let dir = "test_install_target_dir_dir_a";
let scene = TestScenario::new(util_name!());
scene.ucmd().arg("-d").arg(dir).succeeds();
scene.ucmd().arg("-d").arg(dir).succeeds();
let at = &scene.fixtures;
assert!(at.dir_exists(dir));
}
#[test]
fn test_install_failing_not_dir() {
let (at, mut ucmd) = at_and_ucmd!();
@ -87,21 +99,6 @@ fn test_install_component_directories() {
assert!(at.dir_exists(component3));
}
#[test]
fn test_install_component_directories_failing() {
let (at, mut ucmd) = at_and_ucmd!();
let component = "test_install_target_dir_component_d1";
let directories_arg = "-d";
at.mkdir(component);
assert!(ucmd
.arg(directories_arg)
.arg(component)
.fails()
.stderr
.contains("File exists"));
}
#[test]
fn test_install_mode_numeric() {
let (at, mut ucmd) = at_and_ucmd!();