File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -202,7 +202,12 @@ impl Drop for SplitWriter<'_> {
202202 fn drop ( & mut self ) {
203203 if self . options . elide_empty_files && self . size == 0 {
204204 let file_name = self . options . split_name . get ( self . counter ) ;
205- remove_file ( file_name) . expect ( "Failed to elide split" ) ;
205+ // In the case of `echo a | csplit -z - %a%1`, the file
206+ // `xx00` does not exist because the positive offset
207+ // advanced past the end of the input. Since there is no
208+ // file to remove in that case, `remove_file` would return
209+ // an error, so we just ignore it.
210+ let _ = remove_file ( file_name) ;
206211 }
207212 }
208213}
Original file line number Diff line number Diff line change @@ -335,6 +335,16 @@ fn test_skip_to_match_offset() {
335335 }
336336}
337337
338+ #[ test]
339+ fn test_skip_to_match_offset_suppress_empty ( ) {
340+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
341+ ucmd. args ( & [ "-z" , "-" , "%a%1" ] )
342+ . pipe_in ( "a\n " )
343+ . succeeds ( )
344+ . no_output ( ) ;
345+ assert ! ( !at. file_exists( "xx00" ) ) ;
346+ }
347+
338348#[ test]
339349fn test_skip_to_match_negative_offset ( ) {
340350 let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
You can’t perform that action at this time.
0 commit comments