mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
fold: continue processing files after an open error (#12668)
Should make test fold/multiple-files.sh pass
This commit is contained in:
@@ -13,6 +13,7 @@ use unicode_width::UnicodeWidthChar;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UResult, USimpleError};
|
||||
use uucore::format_usage;
|
||||
use uucore::show;
|
||||
use uucore::translate;
|
||||
|
||||
const TAB_WIDTH: usize = 8;
|
||||
@@ -164,7 +165,14 @@ fn fold(
|
||||
stdin_buf = stdin();
|
||||
&mut stdin_buf as &mut dyn Read
|
||||
} else {
|
||||
file_buf = File::open(Path::new(filename)).map_err_context(|| filename.to_string())?;
|
||||
// Like GNU, report the error but keep processing the remaining files.
|
||||
match File::open(Path::new(filename)) {
|
||||
Ok(f) => file_buf = f,
|
||||
Err(e) => {
|
||||
show!(e.map_err_context(|| filename.to_string()));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
&mut file_buf as &mut dyn Read
|
||||
});
|
||||
|
||||
|
||||
@@ -930,6 +930,21 @@ fn test_bytewise_fold_at_read_buffer_boundary() {
|
||||
.stdout_is_bytes(expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_continue_after_missing_file() {
|
||||
// A nonexistent operand must not abort the run: the surrounding files are
|
||||
// still folded, the error is reported on stderr, and the exit status is 1.
|
||||
let ts = TestScenario::new(util_name!());
|
||||
ts.fixtures.write("first.txt", "hello\n");
|
||||
ts.fixtures.write("third.txt", "world\n");
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["first.txt", "absent.txt", "third.txt"])
|
||||
.fails_with_code(1)
|
||||
.stdout_is("hello\nworld\n")
|
||||
.stderr_is("fold: absent.txt: No such file or directory\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_obsolete_syntax() {
|
||||
new_ucmd!()
|
||||
|
||||
Reference in New Issue
Block a user