mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #3382 from sylvestre/du-nox
du: Return non zero error code when dealing with permissions errors
This commit is contained in:
commit
ddf067f188
2 changed files with 23 additions and 3 deletions
|
@ -31,7 +31,7 @@ use std::str::FromStr;
|
|||
use std::time::{Duration, UNIX_EPOCH};
|
||||
use std::{error::Error, fmt::Display};
|
||||
use uucore::display::{print_verbatim, Quotable};
|
||||
use uucore::error::{UError, UResult};
|
||||
use uucore::error::{set_exit_code, UError, UResult};
|
||||
use uucore::format_usage;
|
||||
use uucore::parse_size::{parse_size, ParseSizeError};
|
||||
use uucore::InvalidEncodingHandling;
|
||||
|
@ -301,6 +301,7 @@ fn du(
|
|||
my_stat.path.quote(),
|
||||
e
|
||||
);
|
||||
set_exit_code(1);
|
||||
return Box::new(iter::once(my_stat));
|
||||
}
|
||||
};
|
||||
|
@ -340,8 +341,12 @@ fn du(
|
|||
let description = format!("cannot access {}", entry.path().quote());
|
||||
let error_message = "Permission denied";
|
||||
show_error_custom_description!(description, "{}", error_message);
|
||||
set_exit_code(1);
|
||||
}
|
||||
_ => {
|
||||
set_exit_code(1);
|
||||
show_error!("cannot access {}: {}", entry.path().quote(), error);
|
||||
}
|
||||
_ => show_error!("cannot access {}: {}", entry.path().quote(), error),
|
||||
},
|
||||
},
|
||||
Err(error) => show_error!("{}", error),
|
||||
|
|
|
@ -429,7 +429,7 @@ fn test_du_no_permission() {
|
|||
|
||||
ts.ccmd("chmod").arg("-r").arg(SUB_DIR_LINKS).succeeds();
|
||||
|
||||
let result = ts.ucmd().arg(SUB_DIR_LINKS).run(); // TODO: replace with ".fails()" once `du` is fixed
|
||||
let result = ts.ucmd().arg(SUB_DIR_LINKS).fails();
|
||||
result.stderr_contains(
|
||||
"du: cannot read directory 'subdir/links': Permission denied (os error 13)",
|
||||
);
|
||||
|
@ -449,6 +449,21 @@ fn test_du_no_permission() {
|
|||
_du_no_permission(result.stdout_str());
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
#[cfg(feature = "chmod")]
|
||||
#[test]
|
||||
fn test_du_no_exec_permission() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.mkdir_all("d/no-x/y");
|
||||
|
||||
ts.ccmd("chmod").arg("u=rw").arg("d/no-x").succeeds();
|
||||
|
||||
let result = ts.ucmd().arg("d/no-x").fails();
|
||||
result.stderr_contains("du: cannot access 'd/no-x/y': Permission denied");
|
||||
}
|
||||
|
||||
#[cfg(target_vendor = "apple")]
|
||||
fn _du_no_permission(s: &str) {
|
||||
assert_eq!(s, "0\tsubdir/links\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue