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

head: make head fail when writing to /dev/full #7068

Merged
merged 3 commits into from
Jan 6, 2025

Conversation

DaringCuteSeal
Copy link
Contributor

@DaringCuteSeal DaringCuteSeal commented Jan 4, 2025

Resolves #7029.

Head did not correctly exit when writing to /dev/full because the buffer reader is not properly flushed after the copy operation. This PR addresses the latter.

Changes introduced alongside:

  • refactor head to use error enums instead of directly returning UErrors from USimpleError, thus allowing it to print specific errors like I/O errors (including the "device full" message when writing to /dev/full).
  • the use of the extraneous BufWriter under read_n_lines is deleted as stdout already implements Write. moreover, this will improve performance under specific platforms as io::copy will try to make use of platform-specific write calls that do not use user-space buffer.

@DaringCuteSeal DaringCuteSeal force-pushed the head-dev-full branch 2 times, most recently from 4ae10b0 to 77e734e Compare January 4, 2025 05:05
Copy link

github-actions bot commented Jan 4, 2025

GNU testsuite comparison:

GNU test failed: tests/misc/usage_vs_getopt. tests/misc/usage_vs_getopt is passing on 'main'. Maybe you have to rebase?

@DaringCuteSeal
Copy link
Contributor Author

i think android doesn't like regular users writing to /dev/full so i skipped the check for android.

Copy link

github-actions bot commented Jan 4, 2025

GNU testsuite comparison:

GNU test failed: tests/misc/usage_vs_getopt. tests/misc/usage_vs_getopt is passing on 'main'. Maybe you have to rebase?

@sylvestre
Copy link
Contributor

GNU testsuite comparison:

GNU test failed: tests/misc/usage_vs_getopt. tests/misc/usage_vs_getopt is passing on 'main'. Maybe you have to rebase?

I think it needs to be fixed :)

@DaringCuteSeal
Copy link
Contributor Author

GNU testsuite comparison:

GNU test failed: tests/misc/usage_vs_getopt. tests/misc/usage_vs_getopt is passing on 'main'. Maybe you have to rebase?

I think it needs to be fixed :)

Oh yeah

@DaringCuteSeal
Copy link
Contributor Author

i tried the gnu testsuite against the latest gnu coreutils (git) and it passed. could it be related to #7059 ? I actually have little idea of how the CI is run right now hehe

@DaringCuteSeal
Copy link
Contributor Author

now it automagically works, cool

@@ -37,6 +36,36 @@ mod take;
use take::take_all_but;
use take::take_lines;

#[derive(Error, Debug)]
enum HeadError {
Copy link
Contributor

Choose a reason for hiding this comment

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

much better, thanks :)
I think we should move all the quick_error to thiserror in the code base if you are interested :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that'd be a lot more consistent. I'd definitely do that

@@ -225,6 +251,7 @@ where
let mut stdout = stdout.lock();

io::copy(&mut reader, &mut stdout)?;
stdout.flush()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add a comment explaining why the flush is important

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

Copy link

github-actions bot commented Jan 5, 2025

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@sylvestre sylvestre merged commit 0459369 into uutils:main Jan 6, 2025
65 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.

head: "writes" to /dev/full without error but shouldn't
2 participants