mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
parse_numeric: print mode in octal when the mode is too large (#10208)
This was caught when testing chmod inside of Redox OS. Previously, doing `chmod 10777 file` will cause an error stating that "mode is too large (4607 > 7777", which is both incorrect and contains a missing parenthesis. We now print the large octal value in terms of octal. Co-authored-by: Connor-GH <connor-gh@outlook.com>
This commit is contained in:
@@ -18,7 +18,7 @@ pub fn parse_numeric(fperm: u32, mut mode: &str, considering_dir: bool) -> Resul
|
||||
u32::from_str_radix(mode, 8).map_err(|e| e.to_string())?
|
||||
};
|
||||
if change > 0o7777 {
|
||||
Err(format!("mode is too large ({change} > 7777"))
|
||||
Err(format!("mode is too large ({change:o} > 7777)"))
|
||||
} else {
|
||||
Ok(match op {
|
||||
Some('+') => fperm | change,
|
||||
|
||||
@@ -283,6 +283,34 @@ fn test_chmod_error_permissions() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chmod_permissions_too_large() {
|
||||
let scenario = TestScenario::new(util_name!());
|
||||
let at = &scenario.fixtures;
|
||||
|
||||
at.touch("file");
|
||||
|
||||
scenario
|
||||
.ucmd()
|
||||
.args(&["10777", "file"])
|
||||
.fails_with_code(1)
|
||||
.stderr_is(
|
||||
// spell-checker:disable-next-line
|
||||
"chmod: mode is too large (10777 > 7777)\n",
|
||||
);
|
||||
// test around the boundary of the acceptable octal mode
|
||||
scenario
|
||||
.ucmd()
|
||||
.args(&["10000", "file"])
|
||||
.fails_with_code(1)
|
||||
.stderr_is(
|
||||
// spell-checker:disable-next-line
|
||||
"chmod: mode is too large (10000 > 7777)\n",
|
||||
);
|
||||
at.mkdir("dir");
|
||||
scenario.ucmd().args(&["7777", "dir"]).succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::unreadable_literal)]
|
||||
fn test_chmod_ugo_copy() {
|
||||
|
||||
Reference in New Issue
Block a user