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:
parent
8ef7f394c1
commit
89f8624936
2 changed files with 18 additions and 23 deletions
|
@ -363,14 +363,12 @@ fn directory(paths: Vec<String>, b: Behavior) -> i32 {
|
||||||
for directory in paths.iter() {
|
for directory in paths.iter() {
|
||||||
let path = Path::new(directory);
|
let path = Path::new(directory);
|
||||||
|
|
||||||
if path.exists() {
|
// if the path already exist, don't try to create it again
|
||||||
show_info!("cannot create directory '{}': File exists", path.display());
|
if !path.exists() {
|
||||||
all_successful = false;
|
if let Err(e) = fs::create_dir(directory) {
|
||||||
}
|
show_info!("{}: {}", path.display(), e.to_string());
|
||||||
|
all_successful = false;
|
||||||
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() {
|
if mode::chmod(&path, b.mode()).is_err() {
|
||||||
|
|
|
@ -31,6 +31,18 @@ fn test_install_basic() {
|
||||||
assert!(at.file_exists(&format!("{}/{}", dir, file2)));
|
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]
|
#[test]
|
||||||
fn test_install_failing_not_dir() {
|
fn test_install_failing_not_dir() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
@ -87,21 +99,6 @@ fn test_install_component_directories() {
|
||||||
assert!(at.dir_exists(component3));
|
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]
|
#[test]
|
||||||
fn test_install_mode_numeric() {
|
fn test_install_mode_numeric() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue