Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand: Continue work when one of given files doesn't exist #5873

Merged
merged 2 commits into from
Jan 25, 2024
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
24 changes: 15 additions & 9 deletions src/uu/expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,21 @@
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(),

Check warning on line 478 in src/uu/expand/src/expand.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/expand/src/expand.rs#L478

Added line #L478 was not covered by tests
} {
expand_line(&mut buf, &mut output, ts, options)
.map_err_context(|| "failed to write output".to_string())?;

Check warning on line 481 in src/uu/expand/src/expand.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/expand/src/expand.rs#L481

Added line #L481 was not covered by tests
}
}
Err(e) => {
show_error!("{}", e);
set_exit_code(1);
continue;
}
}
}
Ok(())
Expand Down
9 changes: 9 additions & 0 deletions tests/by-util/test_expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Loading