diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 01b38a7bd..2b0aaa4c4 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -363,14 +363,12 @@ fn directory(paths: Vec, 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() { diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index c47903df3..130713f58 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -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!();