mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
uucore/mode: handle mode 0
Trimming all '0' characters results in an invalid string if the string contained only '0's.
This commit is contained in:
parent
74958794c6
commit
9697c89d17
1 changed files with 14 additions and 12 deletions
|
@ -11,20 +11,22 @@ use libc::{mode_t, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR};
|
|||
|
||||
pub fn parse_numeric(fperm: u32, mut mode: &str) -> Result<u32, String> {
|
||||
let (op, pos) = parse_op(mode, Some('='))?;
|
||||
mode = mode[pos..].trim().trim_start_matches('0');
|
||||
if mode.len() > 4 {
|
||||
Err(format!("mode is too large ({} > 7777)", mode))
|
||||
} else {
|
||||
mode = mode[pos..].trim();
|
||||
match u32::from_str_radix(mode, 8) {
|
||||
Ok(change) => Ok(match op {
|
||||
Ok(change) => {
|
||||
if change > 0o7777 {
|
||||
Err(format!("mode is too large ({} > 7777", mode))
|
||||
} else {
|
||||
Ok(match op {
|
||||
'+' => fperm | change,
|
||||
'-' => fperm & !change,
|
||||
'=' => change,
|
||||
_ => unreachable!(),
|
||||
}),
|
||||
Err(err) => Err(err.to_string()),
|
||||
})
|
||||
}
|
||||
}
|
||||
Err(err) => Err(err.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_symbolic(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue