Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/uu/split/src/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::io::{BufRead, BufReader, BufWriter, ErrorKind, Read, Seek, SeekFrom, Wr
use std::path::Path;
use thiserror::Error;
use uucore::display::Quotable;
use uucore::error::strip_errno;
use uucore::error::{FromIo, UIoError, UResult, USimpleError, UUsageError};
use uucore::translate;

Expand Down Expand Up @@ -1573,7 +1574,10 @@ fn split(settings: &Settings) -> UResult<()> {
}
Strategy::Lines(chunk_size) => {
let mut writer = LineChunkWriter::new(chunk_size, settings)?;
copy(&mut reader, &mut writer)
if let Err(e) = io::copy(&mut reader, &mut writer) {
return Err(USimpleError::new(1, strip_errno(&e).clone()));
}
Ok(())
}
Strategy::Bytes(chunk_size) => {
let mut writer = ByteChunkWriter::new(chunk_size, settings)?;
Expand Down
9 changes: 9 additions & 0 deletions tests/by-util/test_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2068,3 +2068,12 @@ fn test_split_directory_already_exists() {
.no_stdout()
.stderr_is("split: 'xaa': Is a directory\n");
}

#[test]
#[cfg(target_os = "linux")]
fn test_io_error() {
let scene = new_ucmd!().arg("/proc/self/mem").fails_with_code(1);
let stderr = scene.stderr_str();

assert!(stderr == "split: Input/output error\n" || stderr == "split: I/O error\n");
}
Loading