Skip to content

Flush BufWriters, clean up error reporting #7622

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

Merged
merged 8 commits into from
Apr 8, 2025

Conversation

blyxxyz
Copy link
Contributor

@blyxxyz blyxxyz commented Mar 31, 2025

A BufWriter must be flushed when you're done with it, since it'll ignore any write errors when it flushes on dropping. So many utilities would ignore write errors for small outputs. I went through all the BufWriters to add this where it was missing. (Except shuf, which is handled in #7585.)

I also cleaned up some error reporting as I went. sort used to panic on write errors and some other utilities added weird context to errors or no context at all.

All the added flushes have Linux-only tests that use /dev/full. That seemed the easiest way to do it.

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)

We pass a `&mut dyn Write` in anyway, but now that's entirely up to
the caller.
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)

@sylvestre
Copy link
Contributor

do you know if it impacts performances? thanks

@blyxxyz
Copy link
Contributor Author

blyxxyz commented Apr 4, 2025

There shouldn't be any performance impact. They're already flushed automatically on drop, with this change we flush them manually before dropping so we can handle the errors.

The docs say it's "critical" to call flush: https://doc.rust-lang.org/std/io/struct.BufWriter.html
So not doing it was a bug.

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@tertsdiepraam tertsdiepraam merged commit 8040305 into uutils:main Apr 8, 2025
85 of 86 checks passed
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.

4 participants