mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
mkdir: trying to create existing dir is fine
Fixes #1017. test_mkdir_dup_dir asserted that creating an existing directory is an error, but that's not how GNU coreutils behaves. This has been reported in #121, but wasn't fixed (only the `-p` case was).
This commit is contained in:
parent
65b46314a2
commit
67ac0c13b8
2 changed files with 9 additions and 10 deletions
|
@ -119,14 +119,11 @@ fn exec(dirs: Vec<String>, recursive: bool, mode: u16, verbose: bool) -> i32 {
|
||||||
* Wrapper to catch errors, return 1 if failed
|
* Wrapper to catch errors, return 1 if failed
|
||||||
*/
|
*/
|
||||||
fn mkdir(path: &Path, mode: u16, verbose: bool) -> i32 {
|
fn mkdir(path: &Path, mode: u16, verbose: bool) -> i32 {
|
||||||
if path.exists() {
|
if !path.exists() {
|
||||||
show_info!("cannot create directory '{}': File exists", path.display());
|
if let Err(e) = fs::create_dir(path) {
|
||||||
return 1;
|
show_info!("{}: {}", path.display(), e.to_string());
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
if let Err(e) = fs::create_dir(path) {
|
|
||||||
show_info!("{}: {}", path.display(), e.to_string());
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if verbose {
|
if verbose {
|
||||||
|
|
|
@ -16,7 +16,7 @@ fn test_mkdir_mkdir() {
|
||||||
fn test_mkdir_dup_dir() {
|
fn test_mkdir_dup_dir() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
scene.ucmd().arg(TEST_DIR2).succeeds();
|
scene.ucmd().arg(TEST_DIR2).succeeds();
|
||||||
scene.ucmd().arg(TEST_DIR2).fails();
|
scene.ucmd().arg(TEST_DIR2).succeeds();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -30,7 +30,9 @@ fn test_mkdir_mode() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mkdir_parent() {
|
fn test_mkdir_parent() {
|
||||||
new_ucmd!().arg("-p").arg(TEST_DIR4).succeeds();
|
let scene = TestScenario::new(util_name!());
|
||||||
|
scene.ucmd().arg("-p").arg(TEST_DIR4).succeeds();
|
||||||
|
scene.ucmd().arg("-p").arg(TEST_DIR4).succeeds();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue