mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
Get test suite passing again by tweaking error handling in mkdir
Replace `show_error!` with Result<(), int> and `display_error!`
This commit is contained in:
parent
0ee4fb0576
commit
962a6bbf2f
2 changed files with 23 additions and 6 deletions
|
@ -20,6 +20,16 @@ macro_rules! show_error(
|
|||
})
|
||||
)
|
||||
|
||||
// FIXME #211: Transitional until there are no further users of `show_error!`.
|
||||
// Then this can be renamed.
|
||||
#[macro_export]
|
||||
macro_rules! display_error(
|
||||
($($args:expr),+) => ({
|
||||
safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME);
|
||||
safe_writeln!(&mut ::std::io::stderr(), $($args),+);
|
||||
})
|
||||
)
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! show_warning(
|
||||
($($args:expr),+) => ({
|
||||
|
|
|
@ -84,9 +84,10 @@ pub fn uumain(args: Vec<String>) -> int {
|
|||
if dirs.is_empty() {
|
||||
crash!(1, "missing operand");
|
||||
}
|
||||
exec(dirs, mk_parents, mode, verbose_flag);
|
||||
|
||||
return 0;
|
||||
match exec(dirs, mk_parents, mode, verbose_flag) {
|
||||
Ok(()) => return 0,
|
||||
Err(e) => return e
|
||||
}
|
||||
}
|
||||
|
||||
fn print_help(opts: &[getopts::OptGroup]) {
|
||||
|
@ -99,7 +100,7 @@ fn print_help(opts: &[getopts::OptGroup]) {
|
|||
/**
|
||||
* Create the list of new directories
|
||||
*/
|
||||
fn exec(dirs: Vec<String>, mk_parents: bool, mode: FilePermission, verbose: bool) {
|
||||
fn exec(dirs: Vec<String>, mk_parents: bool, mode: FilePermission, verbose: bool) -> Result<(), int> {
|
||||
let mut parent_dirs = Vec::new();
|
||||
if mk_parents {
|
||||
for dir in dirs.iter() {
|
||||
|
@ -118,7 +119,10 @@ fn exec(dirs: Vec<String>, mk_parents: bool, mode: FilePermission, verbose: bool
|
|||
}
|
||||
// Recursively build parent dirs that are needed
|
||||
if !parent_dirs.is_empty() {
|
||||
exec(parent_dirs, mk_parents, mode, verbose);
|
||||
match exec(parent_dirs, mk_parents, mode, verbose) {
|
||||
Ok(()) => ( /* keep going */ ),
|
||||
Err(e) => return Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
for dir in dirs.iter() {
|
||||
|
@ -140,9 +144,12 @@ fn exec(dirs: Vec<String>, mk_parents: bool, mode: FilePermission, verbose: bool
|
|||
} else {
|
||||
format!("directory '{}' already exists", *dir)
|
||||
};
|
||||
show_error!(1, "{}", error_msg);
|
||||
display_error!("{}", error_msg);
|
||||
return Err(1);
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue