diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 3683971133e..4fe156808a5 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -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; @@ -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)?; diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index a5d67402396..a15e67c1fe1 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -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"); +}