Skip to content
Open
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
25 changes: 14 additions & 11 deletions src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,17 +1067,20 @@
}

/// Truncate the file to the final cursor location.
fn truncate(&mut self) {
// Calling `set_len()` may result in an error (for example,
// when calling it on `/dev/null`), but we don't want to
// terminate the process when that happens. Instead, we
// suppress the error by calling `Result::ok()`. This matches
// the behavior of GNU `dd` when given the command-line
// argument `of=/dev/null`.
match self {
Self::Unbuffered(o) => o.truncate().ok(),
Self::Buffered(o) => o.truncate().ok(),
fn truncate(&mut self) -> io::Result<()> {
let result = match self {
Self::Unbuffered(o) => o.truncate(),
Self::Buffered(o) => o.truncate(),
};
// ftruncate returns EINVAL when the destination isn't a regular

Check failure on line 1075 in src/uu/dd/src/dd.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

ERROR: `cspell`: Unknown word 'ftruncate' (file:'src/uu/dd/src/dd.rs', line:1075)
// file (e.g. `of=/dev/null`), which GNU dd silently ignores.
// Anything else (ENOSPC, EROFS, ...) is a real failure we need
// to surface so the user doesn't end up with stale data.
match result {
Ok(()) => Ok(()),
Err(err) if err.kind() == io::ErrorKind::InvalidInput => Ok(()),
Err(err) => Err(err),
}
}

fn write_blocks(&mut self, buf: &[u8]) -> io::Result<WriteStat> {
Expand Down Expand Up @@ -1308,7 +1311,7 @@

// Truncate the file to the final cursor location.
if truncate {
output.truncate();
output.truncate()?;
}

// Print the final read/write statistics.
Expand Down
Loading