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:
Connor-GH
2026-02-03 08:43:48 -06:00
committed by GitHub
parent 312f2e492d
commit 0c5f76c501
2 changed files with 29 additions and 1 deletions
+1 -1
View File
@@ -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,
+28
View File
@@ -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() {