Skip to content

Conversation

@naoNao89
Copy link
Contributor

csplit: create final empty file with --suppress-matched to match GNU (fixes #7286)

Problem

  • With , uutils csplit failed to create the final empty output file when the last split point consumed the trailing input.
  • GNU csplit always creates a final segment after processing patterns; with , that empty final segment is elided.
  • This broke the GNU test (tests/csplit/csplit-suppress-matched.pl) and the scenario:

Root cause

  • Final-file creation was conditional on there being remaining input after pattern processing. If none remained, no final file was created, contrary to GNU semantics.

Fix (minimal, targeted)

  • In , after :
    • If there is remaining input, always create a final split and copy the remainder, then finish.
    • Else, if all patterns were integer-based and is set, create a final (possibly empty) split and finish; elides it when is set.

Tests (Rust integration)

  • Added two Rust tests under to lock down GNU-compatible behavior:
    • (expects sizes 2,2,2,0 and a final empty )
    • (final empty file is correctly elided)

Verification

  • All tests pass locally. The originally reported case now matches GNU.

Relation to PR #7806

Fixes #7286

…ixes uutils#7286)

Problem
- With , uutils csplit failed to create the final empty output file when the last split point consumed the trailing input.
- GNU csplit always creates a final segment after processing patterns; with , that empty final segment is elided.
- This broke the GNU test (tests/csplit/csplit-suppress-matched.pl) and the scenario:

Root cause
- Final-file creation was conditional on there being remaining input after pattern processing. If none remained, no final file was created, contrary to GNU semantics.

Fix (minimal, targeted)
- In , after :
  - If there is remaining input, always create a final split and copy the remainder, then finish.
  - Else, if all patterns were integer-based and  is set, create a final (possibly empty) split and finish;  elides it when  is set.

Tests (Rust integration)
- Added two Rust tests under  to lock down GNU-compatible behavior:
  -  (expects sizes 2,2,2,0 and a final empty )
  -  (final empty file is correctly elided)

Verification
- All  tests pass locally. The originally reported case now matches GNU.

Relation to PR uutils#7806
- uutils#7806 proposes a broader refactor to fix multiple issues, but remains a draft and notes remaining GNU suppress-matched differences.
- This PR provides a small, reviewable fix specifically for uutils#7286, plus precise integration tests to safeguard behavior.

Fixes uutils#7286
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/csplit/csplit-suppress-matched is no longer failing!

@cakebaker cakebaker merged commit ebd8377 into uutils:main Sep 18, 2025
95 checks passed
@cakebaker
Copy link
Contributor

Congrats! The gnu test tests/csplit/csplit-suppress-matched is no longer failing!

Kudos, thanks!

@naoNao89 naoNao89 deleted the fix/csplit-suppress-matched-empty-final-7286 branch September 19, 2025 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

csplit: --suppress-matched incorrectly elides last empty file

2 participants