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

cp: fix symlink-overwrite error-priority #6586

Merged
merged 6 commits into from
Oct 16, 2024
Merged

Conversation

Luv-Ray
Copy link
Contributor

@Luv-Ray Luv-Ray commented Jul 20, 2024

fix #6266

Copy link

GNU testsuite comparison:

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

@BenWiederhake
Copy link
Collaborator

Yes, your change solves a bug, specifically for the scenario you test in test_copy_symlink_overwrite. However, if you try out #6266, which you claim to fix, the error message is unchanged:

target$ rm -f README.md && cp -vs ../README.md ../good/README.md .
'../README.md' -> './README.md'
cp: will not overwrite just-created './README.md' with '../good/README.md'
[$? = 1]
target$ rm -f README.md && cargo run -q cp -vs ../README.md ../good/README.md .
'../README.md' -> './README.md'
cp: will not copy '../good/README.md' through just-created symlink './README.md'
[$? = 1]

@Luv-Ray
Copy link
Contributor Author

Luv-Ray commented Jul 20, 2024

Sorry for missing the test, I think it should be fixed now.

Copy link
Collaborator

@BenWiederhake BenWiederhake left a comment

Choose a reason for hiding this comment

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

Looks correct, and I can't find a counter-example. There's no reason against merging this.

However, this feels a bit like enumerating the test cases and just hard-coding the response to each case. Are those really all cases? I'm a bit worried that this turns into a drawn-out game of whack-a-mole.

@Luv-Ray
Copy link
Contributor Author

Luv-Ray commented Jul 21, 2024

I find some other counter-examples after trying:

let a, b and c be three dictionaries, and run cp a/t b/t c

  • if a/t and b/t both be dictionaries (also add -r), the copy should success, but it will report an error: will not overwrite just-created 'a/t' with 'b/t'.
  • if a/t and b/t both be broken linkes, error should be will not overwrite just-created 'a/t' with 'b/t', but it actually be will not copy 'b/t' through just-created symlink 'a/t' (priority wrong).

I'm not sure whether I should open another issue to report it, I will try to find a more general way to resolve it any way.

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/rm/rm2 is no longer failing!

@BenWiederhake
Copy link
Collaborator

Thank you for searching for more edge cases! Sounds like our logic is completely not aligned with what GNU coreutils does.

I will try to find a more general way to resolve it any way.

That sounds like the correct approach here. There should be a reasonably easy way to write this logic.

The brute-force way to do this is to make a kind of "map" al "all" behaviors, kinda like a truth table (or a Karnaugh map if you're fancy), and then squint at it to see patterns, like "Oh this entire region behaves like X, so that's probably the first if, …", and use that to (re-)implement our logic, which may or may not result in something cleaner than we currently have.

Of course, there are other ways.

@sylvestre sylvestre merged commit 85b0ef1 into uutils:main Oct 16, 2024
68 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.

cp: symlink-overwrite error-priority is wrong
3 participants