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

cat: error when output is input and appending #7260

Merged
merged 2 commits into from
Feb 7, 2025

Conversation

jfinkels
Copy link
Collaborator

@jfinkels jfinkels commented Feb 2, 2025

Change cat so that it terminates with an error message when the input file is the same as the output file and the output file is being appended to. For example,

cat <f >>f
cat: -: input file is output file

Fixes #7165

Copy link

github-actions bot commented Feb 2, 2025

GNU testsuite comparison:

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

@jfinkels jfinkels force-pushed the cat-error-append-same-file branch from f90a322 to 215b8cb Compare February 2, 2025 23:38
Copy link

github-actions bot commented Feb 3, 2025

GNU testsuite comparison:

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

@jfinkels jfinkels marked this pull request as ready for review February 3, 2025 00:43
@sylvestre
Copy link
Contributor

Is it possible to add a test for this?

@jfinkels
Copy link
Collaborator Author

jfinkels commented Feb 4, 2025

There probably is a way to test it, but I'm not sure how to do it from inside Rust. We just need to do something like

touch f
cat <f >>f

and check for the error.

@RenjiSann
Copy link
Collaborator

RenjiSann commented Feb 4, 2025

Here is a test that checks the behavior.

It's the occasion to shout out to the people who engineered the testsuite. It's really easy to use, and it works like a charm. Thank you very much, testsuite maker 🙏

@jfinkels
Copy link
Collaborator Author

jfinkels commented Feb 5, 2025

Thanks @RenjiSann, I've included your commit in this branch.

Copy link

github-actions bot commented Feb 5, 2025

GNU testsuite comparison:

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

@RenjiSann
Copy link
Collaborator

Actually, I have not checked that it worked correctly on every platform, and I haven't cleaned it either, that's why CI is failing ^^;

Copy link

github-actions bot commented Feb 6, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)

tests/by-util/test_cat.rs Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Feb 7, 2025

GNU testsuite comparison:

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

Copy link
Collaborator

@RenjiSann RenjiSann left a comment

Choose a reason for hiding this comment

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

The changes look good to me 👌 :

Please squash all the commits related to the test in a single one to reduce verbosity on the main branch, and e'll be good to go 👍

jfinkels and others added 2 commits February 7, 2025 07:45
Change `cat` so that it terminates with an error message when the input
file is the same as the output file and the output file is being
appended to. For example,

    cat <f >>f
    cat: -: input file is output file

Fixes uutils#7165
@jfinkels jfinkels force-pushed the cat-error-append-same-file branch from 3e62b24 to 9a88526 Compare February 7, 2025 12:45
Copy link

github-actions bot commented Feb 7, 2025

GNU testsuite comparison:

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

@RenjiSann RenjiSann merged commit 569afcc into uutils:main Feb 7, 2025
64 of 65 checks passed
@RenjiSann
Copy link
Collaborator

Thank you for the change !

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.

cat: should error when appending to input file redirected to stdin but doesn't
3 participants