mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
expand: Continue work when one of given files doesn't exist (#5873)
* expand: continues work when one of given files doesn't exist * fixed test for nonexisting file
This commit is contained in:
@@ -471,15 +471,21 @@ fn expand(options: &Options) -> UResult<()> {
|
||||
set_exit_code(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut fh = open(file)?;
|
||||
|
||||
while match fh.read_until(b'\n', &mut buf) {
|
||||
Ok(s) => s > 0,
|
||||
Err(_) => buf.is_empty(),
|
||||
} {
|
||||
expand_line(&mut buf, &mut output, ts, options)
|
||||
.map_err_context(|| "failed to write output".to_string())?;
|
||||
match open(file) {
|
||||
Ok(mut fh) => {
|
||||
while match fh.read_until(b'\n', &mut buf) {
|
||||
Ok(s) => s > 0,
|
||||
Err(_) => buf.is_empty(),
|
||||
} {
|
||||
expand_line(&mut buf, &mut output, ts, options)
|
||||
.map_err_context(|| "failed to write output".to_string())?;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
show_error!("{}", e);
|
||||
set_exit_code(1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -417,3 +417,12 @@ fn test_expand_directory() {
|
||||
.fails()
|
||||
.stderr_contains("expand: .: Is a directory");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nonexisting_file() {
|
||||
new_ucmd!()
|
||||
.args(&["nonexistent", "with-spaces.txt"])
|
||||
.fails()
|
||||
.stderr_contains("expand: nonexistent: No such file or directory")
|
||||
.stdout_contains_line("// !note: file contains significant whitespace");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user