mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #5336 from sylvestre/isdigit
Replace list of digit by is_digit
This commit is contained in:
commit
1a87c31b1e
5 changed files with 26 additions and 35 deletions
|
@ -335,9 +335,7 @@ impl Chmoder {
|
|||
let mut new_mode = fperm;
|
||||
let mut naively_expected_new_mode = new_mode;
|
||||
for mode in cmode_unwrapped.split(',') {
|
||||
// cmode is guaranteed to be Some in this case
|
||||
let arr: &[char] = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
let result = if mode.contains(arr) {
|
||||
let result = if mode.chars().any(|c| c.is_ascii_digit()) {
|
||||
mode::parse_numeric(new_mode, mode, file.is_dir()).map(|v| (v, v))
|
||||
} else {
|
||||
mode::parse_symbolic(new_mode, mode, get_umask(), file.is_dir()).map(|m| {
|
||||
|
@ -352,20 +350,22 @@ impl Chmoder {
|
|||
(m, naive_mode)
|
||||
})
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok((mode, naive_mode)) => {
|
||||
new_mode = mode;
|
||||
naively_expected_new_mode = naive_mode;
|
||||
}
|
||||
Err(f) => {
|
||||
if self.quiet {
|
||||
return Err(ExitCode::new(1));
|
||||
return if self.quiet {
|
||||
Err(ExitCode::new(1))
|
||||
} else {
|
||||
return Err(USimpleError::new(1, f));
|
||||
}
|
||||
Err(USimpleError::new(1, f))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.change_file(fperm, new_mode, file)?;
|
||||
// if a permission would have been removed if umask was 0, but it wasn't because umask was not 0, print an error and fail
|
||||
if (new_mode & !naively_expected_new_mode) != 0 {
|
||||
|
|
|
@ -9,10 +9,7 @@ use uucore::mode;
|
|||
|
||||
/// Takes a user-supplied string and tries to parse to u16 mode bitmask.
|
||||
pub fn parse(mode_string: &str, considering_dir: bool, umask: u32) -> Result<u32, String> {
|
||||
let numbers: &[char] = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
|
||||
// Passing 000 as the existing permissions seems to mirror GNU behavior.
|
||||
if mode_string.contains(numbers) {
|
||||
if mode_string.chars().any(|c| c.is_ascii_digit()) {
|
||||
mode::parse_numeric(0, mode_string, considering_dir)
|
||||
} else {
|
||||
mode::parse_symbolic(0, mode_string, umask, considering_dir)
|
||||
|
|
|
@ -38,14 +38,12 @@ fn get_mode(_matches: &ArgMatches, _mode_had_minus_prefix: bool) -> Result<u32,
|
|||
|
||||
#[cfg(not(windows))]
|
||||
fn get_mode(matches: &ArgMatches, mode_had_minus_prefix: bool) -> Result<u32, String> {
|
||||
let digits: &[char] = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
// Translate a ~str in octal form to u16, default to 777
|
||||
// Not tested on Windows
|
||||
let mut new_mode = DEFAULT_PERM;
|
||||
match matches.get_one::<String>(options::MODE) {
|
||||
Some(m) => {
|
||||
|
||||
if let Some(m) = matches.get_one::<String>(options::MODE) {
|
||||
for mode in m.split(',') {
|
||||
if mode.contains(digits) {
|
||||
if mode.chars().any(|c| c.is_ascii_digit()) {
|
||||
new_mode = mode::parse_numeric(new_mode, m, true)?;
|
||||
} else {
|
||||
let cmode = if mode_had_minus_prefix {
|
||||
|
@ -58,12 +56,10 @@ fn get_mode(matches: &ArgMatches, mode_had_minus_prefix: bool) -> Result<u32, St
|
|||
}
|
||||
}
|
||||
Ok(new_mode)
|
||||
}
|
||||
None => {
|
||||
} else {
|
||||
// If no mode argument is specified return the mode derived from umask
|
||||
Ok(!mode::get_umask() & 0o0777)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
|
|
|
@ -11,8 +11,7 @@ use uucore::mode;
|
|||
pub const MODE_RW_UGO: mode_t = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
|
||||
|
||||
pub fn parse_mode(mode: &str) -> Result<mode_t, String> {
|
||||
let arr: &[char] = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
let result = if mode.contains(arr) {
|
||||
let result = if mode.chars().any(|c| c.is_ascii_digit()) {
|
||||
mode::parse_numeric(MODE_RW_UGO as u32, mode)
|
||||
} else {
|
||||
mode::parse_symbolic(MODE_RW_UGO as u32, mode, true)
|
||||
|
|
|
@ -147,8 +147,7 @@ pub fn parse_mode(mode: &str) -> Result<mode_t, String> {
|
|||
#[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 arr: &[char] = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
let result = if mode.contains(arr) {
|
||||
let result = if mode.chars().any(|c| c.is_ascii_digit()) {
|
||||
parse_numeric(fperm, mode, true)
|
||||
} else {
|
||||
parse_symbolic(fperm, mode, get_umask(), true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue