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

split: fix bug with large arguments to -C #7128

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

jfinkels
Copy link
Collaborator

@jfinkels jfinkels commented Jan 12, 2025

Fix the behavior of split -C when given large arguments. Before this commit, bytes were being greedily assigned to a chunk too aggressively, leading to a situation where a split happened in the middle of a line even though the entire line could have fit within the next chunk. This was appearing for large arguments to -C and long lines that extended beyond the size of the read buffer. This commit fixes the behavior.

I couldn't figure out how to make this work with the existing LineBytesWriter and instead wrote the code as a plain function that loops over each line, writing it if it fits in the chunk or otherwise moving to the next chunk. There may be a way to get it working with the LineBytesWriter, I just couldn't figure it out. The new code will probably be less efficient.

Fixes #7026

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/split/line-bytes is no longer failing!

@jfinkels jfinkels force-pushed the split-line-bytes-large-args branch from 5e5209b to 03c2e53 Compare January 12, 2025 22:17
@jfinkels jfinkels marked this pull request as ready for review January 12, 2025 22:20
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/misc/stdbuf is no longer failing!
Congrats! The gnu test tests/split/line-bytes is no longer failing!

Fix the behavior of `split -C` when given large arguments. Before this
commit, bytes were being greedily assigned to a chunk too aggressively,
leading to a situation where a split happened in the middle of a line
even though the entire line could have fit within the next chunk. This
was appearing for large arguments to `-C` and long lines that extended
beyond the size of the read buffer. This commit fixes the behavior.

Fixes uutils#7026
@sylvestre sylvestre force-pushed the split-line-bytes-large-args branch from 03c2e53 to 071e72f Compare January 13, 2025 08:36
Copy link

GNU testsuite comparison:

GNU test failed: tests/misc/stdbuf. tests/misc/stdbuf is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/split/line-bytes is no longer failing!

@sylvestre sylvestre merged commit bb5c991 into uutils:main Jan 13, 2025
64 of 65 checks passed
sylvestre added a commit that referenced this pull request Jan 13, 2025
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.

split: -C with large argument splits at the wrong place
2 participants