Skip to content
Merged
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
47 changes: 20 additions & 27 deletions src/uu/dd/src/dd.rs
Comment thread
oech3 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -684,22 +684,20 @@ impl Dest {

/// Truncate the underlying file to the current stream position, if possible.
fn truncate(&mut self) -> io::Result<()> {
#[allow(clippy::match_wildcard_for_single_variants)]
match self {
Self::File(f, _) => {
let pos = f.stream_position()?;
// `set_len()` can fail with EINVAL on special outputs such as
Comment thread
oech3 marked this conversation as resolved.
// `/dev/null`; GNU `dd` ignores that. But on a regular file a
// truncate failure (e.g. ENOSPC, read-only fs) means silent data
// loss, so the error must surface there.
match f.set_len(pos) {
Ok(()) => Ok(()),
Err(e) if f.metadata().is_ok_and(|m| m.file_type().is_file()) => Err(e),
Err(_) => Ok(()),
}
}
_ => Ok(()),
let Self::File(f, _) = self else {
return Ok(());
};
let pos = f.stream_position()?;
// `set_len()` can fail with EINVAL on special outputs such as
// `/dev/null`; GNU ignores that. But on a regular file a
// truncate failure (e.g. ENOSPC, read-only fs) means silent data
// loss.
if let Err(e) = f.set_len(pos)
&& f.metadata().is_ok_and(|m| m.file_type().is_file())
{
return Err(e);
}
Ok(())
}

/// Discard the system file cache for the given portion of the destination.
Expand Down Expand Up @@ -1281,18 +1279,13 @@ fn dd_copy(mut i: Input, o: Output) -> io::Result<()> {
if check_and_reset_sigusr1() {
alarm.manual_trigger();
}
match alarm.get_trigger() {
ALARM_TRIGGER_NONE => {}
t @ (ALARM_TRIGGER_TIMER | ALARM_TRIGGER_SIGNAL) => {
let tp = match t {
ALARM_TRIGGER_TIMER => ProgUpdateType::Periodic,
_ => ProgUpdateType::Signal,
};
let prog_update = ProgUpdate::new(rstat, wstat, start.elapsed(), tp);
prog_tx.send(prog_update).unwrap_or(());
}
_ => {}
}
let tp = match alarm.get_trigger() {
ALARM_TRIGGER_TIMER => ProgUpdateType::Periodic,
ALARM_TRIGGER_SIGNAL => ProgUpdateType::Signal,
_ => continue,
};
let prog_update = ProgUpdate::new(rstat, wstat, start.elapsed(), tp);
prog_tx.send(prog_update).unwrap_or(());
}

finalize(o, rstat, wstat, start, &prog_tx, output_thread, truncate)
Expand Down
Loading