mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
mkdir: Silently fail in recursive mode if unable to create directories.
This commit is contained in:
parent
5f9bb70422
commit
e03ab6b554
1 changed files with 10 additions and 8 deletions
|
@ -94,10 +94,10 @@ fn exec(dirs: Vec<String>, recursive: bool, mode: u16, verbose: bool) -> i32 {
|
|||
let path = Path::new(dir);
|
||||
if recursive {
|
||||
let mut pathbuf = PathBuf::new();
|
||||
for component in path.components() {
|
||||
pathbuf.push(component.as_os_str());
|
||||
if !path.is_dir() {
|
||||
status |= mkdir(pathbuf.as_path(), mode, verbose);
|
||||
if !path.is_dir() {
|
||||
for component in path.components() {
|
||||
pathbuf.push(component.as_os_str());
|
||||
mkdir(pathbuf.as_path(), recursive, mode, verbose);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -110,11 +110,11 @@ fn exec(dirs: Vec<String>, recursive: bool, mode: u16, verbose: bool) -> i32 {
|
|||
);
|
||||
status = 1;
|
||||
} else {
|
||||
status |= mkdir(path, mode, verbose);
|
||||
status |= mkdir(path, recursive, mode, verbose);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
status |= mkdir(path, mode, verbose);
|
||||
status |= mkdir(path, recursive, mode, verbose);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,9 +125,11 @@ fn exec(dirs: Vec<String>, recursive: bool, mode: u16, verbose: bool) -> i32 {
|
|||
/**
|
||||
* Wrapper to catch errors, return 1 if failed
|
||||
*/
|
||||
fn mkdir(path: &Path, mode: u16, verbose: bool) -> i32 {
|
||||
fn mkdir(path: &Path, recursive: bool, mode: u16, verbose: bool) -> i32 {
|
||||
if let Err(e) = fs::create_dir(path) {
|
||||
show_info!("{}: {}", path.display(), e.to_string());
|
||||
if !recursive {
|
||||
show_info!("{}: {}", path.display(), e.to_string());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue