diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 62b8b7a7bcf..9335d6ecdca 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -2381,9 +2381,7 @@ fn copy_file( let dest_target_exists = dest.try_exists().unwrap_or(false); // Fail if dest is a dangling symlink or a symlink this program created previously if dest_is_symlink { - if FileInformation::from_path(dest, false) - .map(|info| symlinked_files.contains(&info)) - .unwrap_or(false) + if FileInformation::from_path(dest, false).is_ok_and(|info| symlinked_files.contains(&info)) { return Err(CpError::Error( translate!("cp-error-will-not-copy-through-symlink", "source" => source.quote(), "dest" => dest.quote()), diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index fc1adc537fc..6801f84bbdd 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -29,6 +29,8 @@ use uucore::translate; use std::cmp; use std::env; use std::ffi::OsString; +#[cfg(unix)] +use std::fs::Metadata; use std::fs::{File, OpenOptions}; use std::io::{self, Read, Seek, SeekFrom, Write}; #[cfg(any(target_os = "linux", target_os = "android"))] @@ -273,7 +275,7 @@ impl Source { } } // Get file length before seeking to avoid race condition - let file_len = f.metadata().map(|m| m.len()).unwrap_or(u64::MAX); + let file_len = f.metadata().as_ref().map_or(u64::MAX, Metadata::len); // Try seek first; fall back to read if not seekable match n.try_into().ok().map(|n| f.seek(SeekFrom::Current(n))) { Some(Ok(pos)) => { diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index a4fb32bcb45..fa80458fa2b 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -451,21 +451,16 @@ fn count_files(paths: &[&OsStr], recursive: bool) -> u64 { /// A helper for `count_files` specialized for directories. fn count_files_in_directory(p: &Path) -> u64 { - let entries_count = fs::read_dir(p) - .map(|entries| { - entries - .filter_map(Result::ok) - .map(|entry| { - let file_type = entry.file_type(); - match file_type { - Ok(ft) if ft.is_dir() => count_files_in_directory(&entry.path()), - Ok(_) => 1, - Err(_) => 0, - } - }) - .sum() - }) - .unwrap_or(0); + let entries_count = fs::read_dir(p).map_or(0, |entries| { + entries + .flatten() + .map(|entry| match entry.file_type() { + Ok(ft) if ft.is_dir() => count_files_in_directory(&entry.path()), + Ok(_) => 1, + Err(_) => 0, + }) + .sum() + }); 1 + entries_count } diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 6c6091e92c0..3a213f692ea 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -35,7 +35,7 @@ use std::ffi::{OsStr, OsString}; use std::fs::{File, OpenOptions}; use std::hash::{Hash, Hasher}; use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout}; -use std::num::IntErrorKind; +use std::num::{IntErrorKind, NonZero}; use std::ops::Range; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; @@ -1979,9 +1979,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .get_one::(options::PARALLEL) .map_or_else(|| "0".to_string(), String::from); let num_threads = match settings.threads.parse::() { - Ok(0) | Err(_) => std::thread::available_parallelism() - .map(|n| n.get()) - .unwrap_or(1), + Ok(0) | Err(_) => std::thread::available_parallelism().map_or(1, NonZero::get), Ok(n) => n, }; let _ = rayon::ThreadPoolBuilder::new() diff --git a/src/uucore/src/lib/features/systemd_logind.rs b/src/uucore/src/lib/features/systemd_logind.rs index d34e8cc1729..5869eb69ecd 100644 --- a/src/uucore/src/lib/features/systemd_logind.rs +++ b/src/uucore/src/lib/features/systemd_logind.rs @@ -391,10 +391,10 @@ pub fn read_login_records() -> UResult> { } }; - // Get start time using safe wrapper - let start_time = login::get_session_start_time(&session_id) - .map(|usec| UNIX_EPOCH + std::time::Duration::from_micros(usec)) - .unwrap_or(UNIX_EPOCH); // fallback to epoch if unavailable + // Get start time using safe wrapper, fallback to epoch if unavailable + let start_time = login::get_session_start_time(&session_id).map_or(UNIX_EPOCH, |usec| { + UNIX_EPOCH + std::time::Duration::from_micros(usec) + }); // Get TTY using safe wrapper let mut tty = login::get_session_tty(&session_id)