1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 20:47:46 +00:00

Clean up with changes from Arcterus.

This commit is contained in:
Connor E 2018-05-03 08:40:01 +01:00
parent 9d5631228a
commit 62632faa63

View file

@ -92,27 +92,20 @@ fn exec(dirs: Vec<String>, recursive: bool, mode: u16, verbose: bool) -> i32 {
let empty = Path::new(""); let empty = Path::new("");
for dir in &dirs { for dir in &dirs {
let path = Path::new(dir); let path = Path::new(dir);
if recursive { if !recursive {
status |= mkdir(path, recursive, mode, verbose); if let Some(parent) = path.parent() {
} else {
match path.parent() {
Some(parent) => {
if parent != empty && !parent.exists() { if parent != empty && !parent.exists() {
show_info!( show_info!(
"cannot create directory '{}': No such file or directory", "cannot create directory '{}': No such file or directory",
path.display() path.display()
); );
status = 1; status = 1;
} else { continue;
}
}
}
status |= mkdir(path, recursive, mode, verbose); status |= mkdir(path, recursive, mode, verbose);
} }
}
None => {
status |= mkdir(path, recursive, mode, verbose);
}
}
}
}
status status
} }
@ -120,17 +113,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, recursive: bool, mode: u16, verbose: bool) -> i32 { fn mkdir(path: &Path, recursive: bool, mode: u16, verbose: bool) -> i32 {
if recursive { let create_dir = if recursive { fs::create_dir_all } else { fs::create_dir };
if let Err(e) = fs::create_dir_all(path) { if let Err(e) = create_dir(path) {
show_info!("cannot create directory '{}': {}", path.display(), e.to_string());
return 1;
}
} else {
if let Err(e) = fs::create_dir(path) {
show_info!("{}: {}", path.display(), e.to_string()); show_info!("{}: {}", path.display(), e.to_string());
return 1; return 1;
} }
}
if verbose { if verbose {
show_info!("created directory '{}'", path.display()); show_info!("created directory '{}'", path.display());