mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-03 14:37:45 +00:00
sort: avoid sigpipe errors
By calling `unwrap` we get a panic instead of an abort, and since we mute sigpipe panics for all utilites, no error message will be printed.
This commit is contained in:
parent
ce6d439a1b
commit
816c55dce4
3 changed files with 20 additions and 7 deletions
|
@ -255,7 +255,7 @@ fn write<I: WriteableTmpFile>(
|
||||||
|
|
||||||
fn write_lines<'a, T: Write>(lines: &[Line<'a>], writer: &mut T, separator: u8) {
|
fn write_lines<'a, T: Write>(lines: &[Line<'a>], writer: &mut T, separator: u8) {
|
||||||
for s in lines {
|
for s in lines {
|
||||||
crash_if_err!(1, writer.write_all(s.line.as_bytes()));
|
writer.write_all(s.line.as_bytes()).unwrap();
|
||||||
crash_if_err!(1, writer.write_all(&[separator]));
|
writer.write_all(&[separator]).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -384,13 +384,13 @@ impl<'a> Line<'a> {
|
||||||
|
|
||||||
fn print(&self, writer: &mut impl Write, settings: &GlobalSettings) {
|
fn print(&self, writer: &mut impl Write, settings: &GlobalSettings) {
|
||||||
if settings.zero_terminated && !settings.debug {
|
if settings.zero_terminated && !settings.debug {
|
||||||
crash_if_err!(1, writer.write_all(self.line.as_bytes()));
|
writer.write_all(self.line.as_bytes()).unwrap();
|
||||||
crash_if_err!(1, writer.write_all(b"\0"));
|
writer.write_all(b"\0").unwrap();
|
||||||
} else if !settings.debug {
|
} else if !settings.debug {
|
||||||
crash_if_err!(1, writer.write_all(self.line.as_bytes()));
|
writer.write_all(self.line.as_bytes()).unwrap();
|
||||||
crash_if_err!(1, writer.write_all(b"\n"));
|
writer.write_all(b"\n").unwrap();
|
||||||
} else {
|
} else {
|
||||||
crash_if_err!(1, self.print_debug(settings, writer));
|
self.print_debug(settings, writer).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -913,3 +913,16 @@ fn test_merge_batch_size() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only_fixture("merge_ints_interleaved.expected");
|
.stdout_only_fixture("merge_ints_interleaved.expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_sigpipe_panic() {
|
||||||
|
let mut cmd = new_ucmd!();
|
||||||
|
let mut child = cmd.args(&["ext_sort.txt"]).run_no_wait();
|
||||||
|
// Dropping the stdout should not lead to an error.
|
||||||
|
// The "Broken pipe" error should be silently ignored.
|
||||||
|
drop(child.stdout.take());
|
||||||
|
assert_eq!(
|
||||||
|
String::from_utf8(child.wait_with_output().unwrap().stderr),
|
||||||
|
Ok(String::new())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue