cp: fix symlink-overwrite error-priority
fix #6266
GNU testsuite comparison:
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
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]
Sorry for missing the test, I think it should be fixed now.
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/tandb/tboth 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/tandb/tboth be broken linkes, error should bewill not overwrite just-created 'a/t' with 'b/t', but it actually bewill 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.
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!
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.