Skip to content
Merged
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
1 change: 0 additions & 1 deletion src/uu/split/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/uu/split/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 8 additions & 27 deletions src/uu/split/src/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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")
)),
}
}
11 changes: 11 additions & 0 deletions tests/by-util/test_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Loading