Skip to content
New issue

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

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

Already on GitHub? # to your account

csplit: don't panic on missing suppressed file #7292

Merged
merged 1 commit into from
Feb 10, 2025
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
7 changes: 6 additions & 1 deletion src/uu/csplit/src/csplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ impl Drop for SplitWriter<'_> {
fn drop(&mut self) {
if self.options.elide_empty_files && self.size == 0 {
let file_name = self.options.split_name.get(self.counter);
remove_file(file_name).expect("Failed to elide split");
// In the case of `echo a | csplit -z - %a%1`, the file
// `xx00` does not exist because the positive offset
// advanced past the end of the input. Since there is no
// file to remove in that case, `remove_file` would return
// an error, so we just ignore it.
let _ = remove_file(file_name);
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/by-util/test_csplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ fn test_skip_to_match_offset() {
}
}

#[test]
fn test_skip_to_match_offset_suppress_empty() {
let (at, mut ucmd) = at_and_ucmd!();
ucmd.args(&["-z", "-", "%a%1"])
.pipe_in("a\n")
.succeeds()
.no_output();
assert!(!at.file_exists("xx00"));
}

#[test]
fn test_skip_to_match_negative_offset() {
let (at, mut ucmd) = at_and_ucmd!();
Expand Down
Loading