From 4e7c36d8e6d09d59c18889e5ff537c9432eefa1e Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Sat, 27 Jun 2026 14:09:30 +0900 Subject: [PATCH] split: extract proper errno from OS Co-Authored-By: Devel08 --- src/uu/split/locales/en-US.ftl | 1 - src/uu/split/locales/fr-FR.ftl | 1 - src/uu/split/src/split.rs | 35 ++++++++-------------------------- tests/by-util/test_split.rs | 11 +++++++++++ 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/uu/split/locales/en-US.ftl b/src/uu/split/locales/en-US.ftl index d1e712e3038..c3ad6622a7a 100644 --- a/src/uu/split/locales/en-US.ftl +++ b/src/uu/split/locales/en-US.ftl @@ -39,7 +39,6 @@ split-error-would-overwrite-input = { $file } would overwrite input; aborting split-error-cannot-determine-input-size = { $input }: cannot determine input size split-error-cannot-determine-file-size = { $input }: cannot determine file size split-error-cannot-read-from-input = { $input }: cannot read from input : { $error } -split-error-input-output-error = input/output error split-error-unable-to-open-file = unable to open { $file }; aborting split-error-unable-to-reopen-file = unable to re-open { $file }; aborting split-error-file-descriptor-limit = at file descriptor limit, but no file descriptor left to close. Closed { $count } writers before. diff --git a/src/uu/split/locales/fr-FR.ftl b/src/uu/split/locales/fr-FR.ftl index 832e923a4fd..8d6bbc067f5 100644 --- a/src/uu/split/locales/fr-FR.ftl +++ b/src/uu/split/locales/fr-FR.ftl @@ -37,7 +37,6 @@ split-error-would-overwrite-input = { $file } écraserait l'entrée ; abandon split-error-cannot-determine-input-size = { $input } : impossible de déterminer la taille de l'entrée split-error-cannot-determine-file-size = { $input } : impossible de déterminer la taille du fichier split-error-cannot-read-from-input = { $input } : impossible de lire depuis l'entrée : { $error } -split-error-input-output-error = erreur d'entrée/sortie split-error-unable-to-open-file = impossible d'ouvrir { $file } ; abandon split-error-unable-to-reopen-file = impossible de rouvrir { $file } ; abandon split-error-file-descriptor-limit = limite de descripteurs de fichiers atteinte, mais aucun descripteur de fichier à fermer. { $count } écrivains fermés auparavant. diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 00aff099654..17c6e982dc1 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -26,12 +26,9 @@ use std::io::{BufRead, BufReader, ErrorKind, Read, Seek, SeekFrom, Write, stdin} use std::path::Path; use thiserror::Error; use uucore::display::Quotable; -use uucore::error::{FromIo, UIoError, UResult, USimpleError, UUsageError}; -use uucore::translate; - +use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::parser::parse_size::parse_size_u64; - -use uucore::uio_error; +use uucore::translate; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { @@ -1339,32 +1336,16 @@ fn split(settings: &Settings) -> UResult<()> { } Strategy::Lines(chunk_size) => { let mut writer = LineChunkWriter::new(chunk_size, settings)?; - copy(&mut reader, &mut writer) + // todo: distinct read error and write error + io::copy(&mut reader, &mut writer)?; + Ok(()) } Strategy::Bytes(chunk_size) => { let mut writer = ByteChunkWriter::new(chunk_size, settings)?; - copy(&mut reader, &mut writer) + // todo: distinct read error and write error + io::copy(&mut reader, &mut writer)?; + Ok(()) } Strategy::LineBytes(chunk_size) => line_bytes(settings, &mut reader, chunk_size as usize), } } - -fn copy(reader: &mut impl Read, writer: &mut impl Write) -> UResult<()> { - match io::copy(reader, writer) { - Ok(_) => Ok(()), - // TODO Since the writer object controls the creation of - // new files, we need to rely on the `io::Result` - // returned by its `write()` method to communicate any - // errors to this calling scope. If a new file cannot be - // created because we have exceeded the number of - // allowable filenames, we use `ErrorKind::Other` to - // indicate that. A special error message needs to be - // printed in that case. - Err(e) if e.kind() == ErrorKind::Other => Err(USimpleError::new(1, format!("{e}"))), - Err(e) => Err(uio_error!( - e, - "{}", - translate!("split-error-input-output-error") - )), - } -} diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index c5dfd7174f8..ffe256100fe 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -2092,3 +2092,14 @@ fn test_split_directory_already_exists() { .no_stdout() .stderr_is("split: 'xaa': Is a directory\n"); } + +#[test] +#[cfg(all(target_os = "linux", target_env = "gnu"))] +fn test_io_error() { + // /proc/self/mem causes EIO + new_ucmd!() + .arg("/proc/self/mem") + .fails_with_code(1) + //todo: add file path with proper distinction of input/output + .stderr_contains("Input/output error\n"); +}