From 11e77c72d43f53e4d3f5e2c0da4b3317fd7552d7 Mon Sep 17 00:00:00 2001 From: Martin Kunkel Date: Sat, 6 Dec 2025 10:16:56 +0000 Subject: [PATCH] uucore: mode parsing: support comma-separated mode Parsing in uucore::mode did not support multiple mode chunks separated by commas, e.g. "ug+rw,o+r" --- src/uucore/src/lib/features/mode.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/uucore/src/lib/features/mode.rs b/src/uucore/src/lib/features/mode.rs index 50ed8c97c..323830d76 100644 --- a/src/uucore/src/lib/features/mode.rs +++ b/src/uucore/src/lib/features/mode.rs @@ -139,21 +139,16 @@ fn parse_change(mode: &str, fperm: u32, considering_dir: bool) -> (u32, usize) { #[allow(clippy::unnecessary_cast)] pub fn parse_mode(mode: &str) -> Result { - #[cfg(all( - not(target_os = "freebsd"), - not(target_vendor = "apple"), - not(target_os = "android") - ))] - let fperm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - #[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "android"))] - let fperm = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; + let mut new_mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; - let result = if mode.chars().any(|c| c.is_ascii_digit()) { - parse_numeric(fperm as u32, mode, true) - } else { - parse_symbolic(fperm as u32, mode, get_umask(), true) - }; - result.map(|mode| mode as mode_t) + for mode_chunk in mode.split(',') { + new_mode = if mode_chunk.chars().any(|c| c.is_ascii_digit()) { + parse_numeric(new_mode, mode_chunk, true)? + } else { + parse_symbolic(new_mode, mode_chunk, get_umask(), true)? + }; + } + Ok(new_mode as mode_t) } pub fn get_umask() -> u32 { @@ -202,4 +197,9 @@ mod test { assert_eq!(super::parse_mode("+100").unwrap(), 0o766); assert_eq!(super::parse_mode("-4").unwrap(), 0o662); } + + #[test] + fn multiple_modes() { + assert_eq!(super::parse_mode("+100,+010").unwrap(), 0o776); + } }