Merge pull request #10625 from xtqqczze/clippy/map_unwrap_or

clippy: fix nightly map_unwrap_or lint
This commit is contained in:
Dorian Péron
2026-02-02 20:13:28 +01:00
committed by GitHub
5 changed files with 20 additions and 27 deletions
+1 -3
View File
@@ -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()),
+3 -1
View File
@@ -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)) => {
+10 -15
View File
@@ -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
}
+2 -4
View File
@@ -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;
@@ -2107,9 +2107,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.get_one::<String>(options::PARALLEL)
.map_or_else(|| "0".to_string(), String::from);
let num_threads = match settings.threads.parse::<usize>() {
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()
@@ -391,10 +391,10 @@ pub fn read_login_records() -> UResult<Vec<SystemdLoginRecord>> {
}
};
// 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)