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/cat/src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ pub fn is_unsafe_overwrite<I: AsHandleRef, O: AsHandleRef>(input: &I, output: &O
}

// Check if the output file is empty
FileInformation::from_file(output)
.map(|info| info.file_size() > 0)
.unwrap_or(false)
FileInformation::from_file(output).is_ok_and(|info| info.file_size() > 0)
}

/// Get the file path for a file handle
Expand Down
58 changes: 27 additions & 31 deletions src/uu/chcon/src/chcon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,33 +537,29 @@ fn process_file(
let mut result = Ok(());

match entry.flags() {
fts_sys::FTS_D => {
if options.recursive_mode.is_recursive() {
if root_dev_ino_check(root_dev_ino, file_dev_ino) {
// This happens e.g., with "chcon -R --preserve-root ... /"
// and with "chcon -RH --preserve-root ... symlink-to-root".
root_dev_ino_warn(&file_full_name);

// Tell fts not to traverse into this hierarchy.
let _ignored = fts.set(fts_sys::FTS_SKIP);

// Ensure that we do not process "/" on the second visit.
let _ignored = fts.read_next_entry();

return Err(err(
translate!("chcon-op-modifying-root-path"),
io::ErrorKind::PermissionDenied,
));
}
fts_sys::FTS_D if options.recursive_mode.is_recursive() => {
if root_dev_ino_check(root_dev_ino, file_dev_ino) {
// This happens e.g., with "chcon -R --preserve-root ... /"
// and with "chcon -RH --preserve-root ... symlink-to-root".
root_dev_ino_warn(&file_full_name);

return Ok(());
// Tell fts not to traverse into this hierarchy.
let _ignored = fts.set(fts_sys::FTS_SKIP);

// Ensure that we do not process "/" on the second visit.
let _ignored = fts.read_next_entry();

return Err(err(
translate!("chcon-op-modifying-root-path"),
io::ErrorKind::PermissionDenied,
));
}

return Ok(());
}

fts_sys::FTS_DP => {
if !options.recursive_mode.is_recursive() {
return Ok(());
}
fts_sys::FTS_DP if !options.recursive_mode.is_recursive() => {
return Ok(());
}

fts_sys::FTS_NS => {
Expand All @@ -585,14 +581,14 @@ fn process_file(

fts_sys::FTS_DNR => result = fts_err(translate!("chcon-op-reading-directory")),

fts_sys::FTS_DC => {
if cycle_warning_required(options.recursive_mode.fts_open_options(), &entry) {
emit_cycle_warning(&file_full_name);
return Err(err(
translate!("chcon-op-reading-cyclic-directory"),
io::ErrorKind::InvalidData,
));
}
fts_sys::FTS_DC
if cycle_warning_required(options.recursive_mode.fts_open_options(), &entry) =>
{
emit_cycle_warning(&file_full_name);
return Err(err(
translate!("chcon-op-reading-cyclic-directory"),
io::ErrorKind::InvalidData,
));
}

_ => {}
Expand Down
6 changes: 2 additions & 4 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,10 +1134,8 @@ impl Options {
options::PRESERVE => {
attributes = attributes.union(&Attributes::parse_iter(val.into_iter())?);
}
options::NO_PRESERVE => {
if !val.is_empty() {
attributes = attributes.diff(&Attributes::parse_iter(val.into_iter())?);
}
options::NO_PRESERVE if !val.is_empty() => {
attributes = attributes.diff(&Attributes::parse_iter(val.into_iter())?);
}
_ => (),
}
Expand Down
8 changes: 3 additions & 5 deletions src/uu/date/src/format_modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,9 @@ fn apply_modifiers(value: &str, parsed: &ParsedSpec<'_>) -> Result<String, Forma
uppercase = true;
swap_case = false; // ^ overrides #
}
'#' => {
if !uppercase {
// Only apply # if ^ hasn't been set
swap_case = true;
}
'#' if !uppercase => {
// Only apply # if ^ hasn't been set
swap_case = true;
}
'+' => {
force_sign = true;
Expand Down
2 changes: 1 addition & 1 deletion src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ impl Input<'_> {
bytes_total += rlen;
reads_partial += 1;
let padding = vec![pad; target_len - rlen];
buf.splice(base_idx + rlen..next_blk, padding.into_iter());
buf.splice(base_idx + rlen..next_blk, padding);
}
rlen => {
bytes_total += rlen;
Expand Down
2 changes: 1 addition & 1 deletion src/uu/dircolors/src/dircolors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ where
let mut state = ParseState::Global;
let mut saw_colorterm_match = false;

for (num, line) in (1..).zip(user_input.into_iter()) {
for (num, line) in (1..).zip(user_input) {
let line = line.borrow().purify();
if line.is_empty() {
continue;
Expand Down
59 changes: 28 additions & 31 deletions src/uu/od/src/od.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,38 +132,35 @@ impl OdOptions {

let formats = parse_format_flags(args).map_err(|e| USimpleError::new(1, e))?;

let mut line_bytes = match matches.get_one::<String>(options::WIDTH) {
None => 16,
Some(s) => {
if matches.value_source(options::WIDTH) == Some(ValueSource::CommandLine) {
let width_display = option_display_name(args, options::WIDTH, Some('w'));
let parsed = parse_number_of_bytes(s).map_err(|e| {
USimpleError::new(1, format_error_message(&e, s, &width_display))
})?;
if parsed == 0 {
return Err(USimpleError::new(
1,
translate!(
"od-error-invalid-argument",
"option" => width_display.clone(),
"value" => s.quote()
),
));
}
usize::try_from(parsed).map_err(|_| {
USimpleError::new(
1,
translate!(
"od-error-argument-too-large",
"option" => width_display.clone(),
"value" => s.quote()
),
)
})?
} else {
16
}
let mut line_bytes = if let (Some(s), Some(ValueSource::CommandLine)) = (
matches.get_one::<String>(options::WIDTH),
matches.value_source(options::WIDTH),
) {
let width_display = option_display_name(args, options::WIDTH, Some('w'));
let parsed = parse_number_of_bytes(s)
.map_err(|e| USimpleError::new(1, format_error_message(&e, s, &width_display)))?;
if parsed == 0 {
return Err(USimpleError::new(
1,
translate!(
"od-error-invalid-argument",
"option" => width_display.clone(),
"value" => s.quote()
),
));
}
usize::try_from(parsed).map_err(|_| {
USimpleError::new(
1,
translate!(
"od-error-argument-too-large",
"option" => width_display.clone(),
"value" => s.quote()
),
)
})?
} else {
16
};

let min_bytes = formats.iter().fold(1, |max, next| {
Expand Down
6 changes: 3 additions & 3 deletions src/uu/od/src/parse_formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn parse_format_flags(args: &[String]) -> Result<Vec<ParsedFormatterItemInfo
for arg in arg_iter {
if expect_type_string {
let v = parse_type_string(arg)?;
formats.extend(v.into_iter());
formats.extend(v);
expect_type_string = false;
} else if arg.starts_with("--") {
if arg.len() == 2 {
Expand All @@ -130,7 +130,7 @@ pub fn parse_format_flags(args: &[String]) -> Result<Vec<ParsedFormatterItemInfo
if arg.starts_with("--format=") {
let params: String = arg.chars().skip_while(|c| *c != '=').skip(1).collect();
let v = parse_type_string(&params)?;
formats.extend(v.into_iter());
formats.extend(v);
}
if arg == "--format" {
expect_type_string = true;
Expand All @@ -154,7 +154,7 @@ pub fn parse_format_flags(args: &[String]) -> Result<Vec<ParsedFormatterItemInfo
}
if !format_spec.is_empty() {
let v = parse_type_string(&format_spec)?;
formats.extend(v.into_iter());
formats.extend(v);
expect_type_string = false;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/uu/tail/src/follow/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl Observer {
*/
}
}
EventKind::Modify(ModifyKind::Name(RenameMode::Both)) => {
EventKind::Modify(ModifyKind::Name(RenameMode::Both))
/*
NOTE: For `tail -f a`, keep tracking additions to b after `mv a b`
(gnu/tests/tail-2/descriptor-vs-rename.sh)
Expand All @@ -457,7 +457,7 @@ impl Observer {
TODO: [2022-05; jhscheer] add test for this bug
*/

if self.follow_descriptor() {
if self.follow_descriptor() => {
let new_path = event.paths.last().unwrap();
paths.push(new_path.clone());

Expand All @@ -472,7 +472,6 @@ impl Observer {
let _ = self.watcher_rx.as_mut().unwrap().unwatch(event_path);
self.watcher_rx.as_mut().unwrap().watch_with_parent(new_path)?;
}
}
_ => {}
}
Ok(paths)
Expand Down
4 changes: 1 addition & 3 deletions src/uucore/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,7 @@ fn embed_locale_file(
/// Check if we are cross-compiling for WASI (build.rs runs on the host,
/// so `#[cfg(target_os = "wasi")]` does not work here).
fn is_wasi_target() -> bool {
env::var("CARGO_CFG_TARGET_OS")
.map(|os| os == "wasi")
.unwrap_or(false)
env::var("CARGO_CFG_TARGET_OS").is_ok_and(|os| os == "wasi")
}

/// For WASI/WASM builds, embed ALL available .ftl files in a locale
Expand Down
11 changes: 5 additions & 6 deletions src/uucore/src/lib/features/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,11 @@ pub fn canonicalize<P: AsRef<Path>>(
}
result.pop();
}
Err(e) => {
if miss_mode == MissingHandling::Existing
|| (miss_mode == MissingHandling::Normal && !parts.is_empty())
{
return Err(e);
}
Err(e)
if (miss_mode == MissingHandling::Existing
|| (miss_mode == MissingHandling::Normal && !parts.is_empty())) =>
{
return Err(e);
}
_ => {}
}
Expand Down
4 changes: 1 addition & 3 deletions src/uucore/src/lib/features/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ pub fn splice_exact(source: &impl AsFd, target: &impl AsFd, len: usize) -> std::
#[inline]
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn might_fuse(source: &impl AsFd) -> bool {
rustix::fs::fstatfs(source)
.map(|stats| stats.f_type == 0x6573_5546) // FUSE magic number, too many platform specific clippy warning with const
.unwrap_or(true)
rustix::fs::fstatfs(source).map_or(true, |stats| stats.f_type == 0x6573_5546) // FUSE magic number, too many platform specific clippy warning with const
}

/// Return verified /dev/null
Expand Down
8 changes: 3 additions & 5 deletions src/uucore/src/lib/features/uptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,9 @@ mod tests {
);

// Boot time should be before current time
let now = Timestamp::now().as_second();
assert!(
(boot_time as i64) < now,
"Boot time should be before current time"
);
let boot_time = Timestamp::from_second(boot_time).unwrap();
let now = Timestamp::now();
assert!(boot_time < now, "Boot time should be before current time");
}

/// Test that get_uptime always succeeds on macOS due to sysctl fallback.
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3376,7 +3376,7 @@ fn test_check_blake3_tagged(
None => String::new(),
};

let tagged = format!("BLAKE3{len} (FILE) = {digest}",);
let tagged = format!("BLAKE3{len} (FILE) = {digest}");

ucmd.arg("-c")
.arg("-a")
Expand Down
6 changes: 2 additions & 4 deletions tests/by-util/test_df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,8 +1054,7 @@ fn test_nonexistent_file() {
fn test_df_all_shows_binfmt_misc() {
// Check if binfmt_misc is mounted
let is_mounted = std::fs::read_to_string("/proc/self/mountinfo")
.map(|content| content.lines().any(|line| line.contains("binfmt_misc")))
.unwrap_or(false);
.is_ok_and(|content| content.lines().any(|line| line.contains("binfmt_misc")));

if is_mounted {
let output = new_ucmd!()
Expand All @@ -1076,8 +1075,7 @@ fn test_df_all_shows_binfmt_misc() {
fn test_df_hides_binfmt_misc_by_default() {
// Check if binfmt_misc is mounted
let is_mounted = std::fs::read_to_string("/proc/self/mountinfo")
.map(|content| content.lines().any(|line| line.contains("binfmt_misc")))
.unwrap_or(false);
.is_ok_and(|content| content.lines().any(|line| line.contains("binfmt_misc")));

if is_mounted {
let output = new_ucmd!()
Expand Down
3 changes: 1 addition & 2 deletions tests/uutests/src/lib/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ pub fn is_locale_available(locale: &str) -> bool {
.env("LC_ALL", locale)
.arg("charmap")
.output()
.map(|o| String::from_utf8_lossy(&o.stdout).trim() == "UTF-8")
.unwrap_or(false)
.is_ok_and(|o| String::from_utf8_lossy(&o.stdout).trim() == "UTF-8")
}

/// Read a test scenario fixture, returning its bytes
Expand Down
Loading