Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
4 changes: 3 additions & 1 deletion src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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)) => {
Expand Down
25 changes: 10 additions & 15 deletions src/uu/rm/src/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1979,9 +1979,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()
Expand Down
8 changes: 4 additions & 4 deletions src/uucore/src/lib/features/systemd_logind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading