1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Merge pull request #7292 from jfinkels/csplit-dont-panic-no-file

csplit: don't panic on missing suppressed file
This commit is contained in:
Daniel Hofstetter 2025-02-10 09:03:17 +01:00 committed by GitHub
commit fd94d36842
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View file

@ -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);
}
}
}

View file

@ -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!();