Skip to content

Commit

Permalink
head: Update error string on disk-full error.
Browse files Browse the repository at this point in the history
Fix for issue #7271.
Update head to print identical error to GNU-head on disk-full scenario.
Fixes all issues with head-write-error.sh test.
  • Loading branch information
karlmcdowall committed Feb 5, 2025
1 parent ee0d178 commit 90ce931
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/uu/head/src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

use clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
use std::ffi::OsString;
use std::io::ErrorKind::StorageFull;
use std::io::{self, ErrorKind, Read, Seek, SeekFrom, Write};
use std::num::TryFromIntError;
use thiserror::Error;
use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult};
use uucore::error::{strip_errno, FromIo, UError, UResult};
use uucore::line_ending::LineEnding;
use uucore::lines::lines;
use uucore::{format_usage, help_about, help_usage, show};
Expand Down Expand Up @@ -56,6 +57,9 @@ enum HeadError {

#[error("{0}")]
MatchOption(String),

#[error("error writing 'standard output': {}", strip_errno(.err))]
WriteError { err: io::Error },
}

impl UError for HeadError {
Expand Down Expand Up @@ -543,11 +547,16 @@ fn uu_head(options: &HeadOptions) -> UResult<()> {
} else {
file
};
return Err(HeadError::Io {
name: name.to_string(),
err: e,
match e.kind() {
StorageFull => return Err(HeadError::WriteError { err: e }.into()),
_ => {
return Err(HeadError::Io {
name: name.to_string(),
err: e,
}
.into())
}
}
.into());
}
first = false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ fn test_write_to_dev_full() {
.pipe_in_fixture(INPUT)
.set_stdout(dev_full)
.run()
.stderr_contains("No space left on device");
.stderr_contains("error writing 'standard output': No space left on device");
}
}
}

0 comments on commit 90ce931

Please sign in to comment.