mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
split: catch broken pipe error for round robin strategy
The broken pipe error is not handled in the case of the round robin strategy (typically used with --filter). Align to the other strategies to silence that error in that use case too. fixes #5191 Signed-off-by: Guillaume Ranquet <granquet@baylibre.com>
This commit is contained in:
parent
2bcb3c2363
commit
d4217c5a12
2 changed files with 22 additions and 4 deletions
|
@ -1282,7 +1282,7 @@ fn split_into_n_chunks_by_line_round_robin<R>(
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
reader: &mut R,
|
reader: &mut R,
|
||||||
num_chunks: u64,
|
num_chunks: u64,
|
||||||
) -> UResult<()>
|
) -> std::io::Result<()>
|
||||||
where
|
where
|
||||||
R: BufRead,
|
R: BufRead,
|
||||||
{
|
{
|
||||||
|
@ -1293,7 +1293,7 @@ where
|
||||||
settings.suffix_length,
|
settings.suffix_length,
|
||||||
settings.suffix_type,
|
settings.suffix_type,
|
||||||
settings.suffix_start,
|
settings.suffix_start,
|
||||||
)?;
|
).map_err(|e| io::Error::new(ErrorKind::Other, format!("{e}")))?;
|
||||||
|
|
||||||
// Create one writer for each chunk. This will create each
|
// Create one writer for each chunk. This will create each
|
||||||
// of the underlying files (if not in `--filter` mode).
|
// of the underlying files (if not in `--filter` mode).
|
||||||
|
@ -1301,7 +1301,7 @@ where
|
||||||
for _ in 0..num_chunks {
|
for _ in 0..num_chunks {
|
||||||
let filename = filename_iterator
|
let filename = filename_iterator
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| USimpleError::new(1, "output file suffixes exhausted"))?;
|
.ok_or_else(|| io::Error::new(ErrorKind::Other, "output file suffixes exhausted"))?;
|
||||||
let writer = settings.instantiate_current_writer(filename.as_str())?;
|
let writer = settings.instantiate_current_writer(filename.as_str())?;
|
||||||
writers.push(writer);
|
writers.push(writer);
|
||||||
}
|
}
|
||||||
|
@ -1346,7 +1346,13 @@ fn split(settings: &Settings) -> UResult<()> {
|
||||||
kth_chunk_by_line(settings, &mut reader, chunk_number, num_chunks)
|
kth_chunk_by_line(settings, &mut reader, chunk_number, num_chunks)
|
||||||
}
|
}
|
||||||
Strategy::Number(NumberType::RoundRobin(num_chunks)) => {
|
Strategy::Number(NumberType::RoundRobin(num_chunks)) => {
|
||||||
split_into_n_chunks_by_line_round_robin(settings, &mut reader, num_chunks)
|
match split_into_n_chunks_by_line_round_robin(settings, &mut reader, num_chunks) {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(e) => match e.kind() {
|
||||||
|
ErrorKind::BrokenPipe => Ok(()),
|
||||||
|
_ => Err(USimpleError::new(1, format!("{e}"))),
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Strategy::Number(_) => Err(USimpleError::new(1, "-n mode not yet fully implemented")),
|
Strategy::Number(_) => Err(USimpleError::new(1, "-n mode not yet fully implemented")),
|
||||||
Strategy::Lines(chunk_size) => {
|
Strategy::Lines(chunk_size) => {
|
||||||
|
|
|
@ -299,6 +299,18 @@ fn test_filter_command_fails() {
|
||||||
.fails();
|
.fails();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn test_filter_broken_pipe() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let name = "filter-big-input";
|
||||||
|
|
||||||
|
RandomFile::new(&at, name).add_lines(1024 * 10);
|
||||||
|
ucmd
|
||||||
|
.args(&["--filter=head -c1 > /dev/null", "-n", "r/1", name])
|
||||||
|
.succeeds();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_split_lines_number() {
|
fn test_split_lines_number() {
|
||||||
// Test if stdout/stderr for '--lines' option is correct
|
// Test if stdout/stderr for '--lines' option is correct
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue