Skip to content

Commit 47c17df

Browse files
oech3cakebaker
authored andcommitted
dd: remove collapsible_if
1 parent 7d7ba48 commit 47c17df

1 file changed

Lines changed: 40 additions & 39 deletions

File tree

src/uu/dd/src/dd.rs

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,17 @@ impl Source {
256256
}
257257
#[cfg(unix)]
258258
Self::StdinFile(f) => {
259-
if let Ok(Some(len)) = try_get_len_of_block_device(f) {
260-
if len < n {
261-
// GNU compatibility:
262-
// this case prints the stats but sets the exit code to 1
263-
show_error!(
264-
"{}",
265-
translate!("dd-error-cannot-skip-invalid", "file" => "standard input")
266-
);
267-
set_exit_code(1);
268-
return Ok(len);
269-
}
259+
if let Ok(Some(len)) = try_get_len_of_block_device(f)
260+
&& len < n
261+
{
262+
// GNU compatibility:
263+
// this case prints the stats but sets the exit code to 1
264+
show_error!(
265+
"{}",
266+
translate!("dd-error-cannot-skip-invalid", "file" => "standard input")
267+
);
268+
set_exit_code(1);
269+
return Ok(len);
270270
}
271271
// Get file length before seeking to avoid race condition
272272
let file_len = f.metadata().as_ref().map_or(u64::MAX, Metadata::len);
@@ -381,14 +381,16 @@ impl<'a> Input<'a> {
381381
#[cfg(unix)]
382382
let mut src = Source::stdin_as_file();
383383
#[cfg(unix)]
384-
if let Source::StdinFile(f) = &src {
385-
if settings.iflags.directory && !f.metadata()?.is_dir() {
386-
return Err(USimpleError::new(
387-
1,
388-
translate!("dd-error-not-directory", "file" => "standard input"),
389-
));
390-
}
384+
if let Source::StdinFile(f) = &src
385+
&& settings.iflags.directory
386+
&& !f.metadata()?.is_dir()
387+
{
388+
return Err(USimpleError::new(
389+
1,
390+
translate!("dd-error-not-directory", "file" => "standard input"),
391+
));
391392
}
393+
392394
if settings.skip > 0 {
393395
src.skip(settings.skip, settings.ibs)?;
394396
}
@@ -655,17 +657,17 @@ impl Dest {
655657
Self::Stdout(stdout) => io::copy(&mut io::repeat(0).take(n), stdout),
656658
Self::File(f, _) => {
657659
#[cfg(unix)]
658-
if let Ok(Some(len)) = try_get_len_of_block_device(f) {
659-
if len < n {
660-
// GNU compatibility:
661-
// this case prints the stats but sets the exit code to 1
662-
show_error!(
663-
"{}",
664-
translate!("dd-error-cannot-seek-invalid", "output" => "standard output")
665-
);
666-
set_exit_code(1);
667-
return Ok(len);
668-
}
660+
if let Ok(Some(len)) = try_get_len_of_block_device(f)
661+
&& len < n
662+
{
663+
// GNU compatibility:
664+
// this case prints the stats but sets the exit code to 1
665+
show_error!(
666+
"{}",
667+
translate!("dd-error-cannot-seek-invalid", "output" => "standard output")
668+
);
669+
set_exit_code(1);
670+
return Ok(len);
669671
}
670672
f.seek(SeekFrom::Current(n.try_into().unwrap()))
671673
}
@@ -1174,10 +1176,14 @@ fn dd_copy(mut i: Input, o: Output) -> io::Result<()> {
11741176
let alarm = Alarm::with_interval(Duration::from_secs(1));
11751177

11761178
#[cfg(target_os = "linux")]
1177-
if let Err(e) = install_sigusr1_handler() {
1178-
if i.settings.status != Some(StatusLevel::None) {
1179-
eprintln!("{}\n\t{e}", translate!("dd-warning-signal-handler"));
1180-
}
1179+
if let Err(e) = install_sigusr1_handler()
1180+
&& i.settings.status != Some(StatusLevel::None)
1181+
{
1182+
let _ = writeln!(
1183+
io::stderr(),
1184+
"{}\n\t{e}",
1185+
translate!("dd-warning-signal-handler")
1186+
);
11811187
}
11821188

11831189
// Index in the input file where we are reading bytes and in
@@ -1498,12 +1504,7 @@ fn try_get_len_of_block_device(file: &mut File) -> io::Result<Option<u64>> {
14981504
/// Decide whether the named file is a named pipe, also known as a FIFO.
14991505
#[cfg(unix)]
15001506
fn is_fifo(filename: &str) -> bool {
1501-
if let Ok(metadata) = std::fs::metadata(filename) {
1502-
if metadata.file_type().is_fifo() {
1503-
return true;
1504-
}
1505-
}
1506-
false
1507+
std::fs::metadata(filename).is_ok_and(|m| m.file_type().is_fifo())
15071508
}
15081509

15091510
#[uucore::main]

0 commit comments

Comments
 (0)