coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

cp: correctly copy ancestor dirs in --parents mode

Open jfinkels opened this issue 3 years ago • 5 comments

Fix a bug where cp failed to copy ancestor directories when using the --parents option. For example, before this commit:

$ mkdir -p a/b/c d
$ cp --parents a/b/c d
$ find d
d
d/c

After this commit

$ mkdir -p a/b/c d
$ cp --parents a/b/c d
$ find d
d
d/a
d/a/b
d/a/b/c

This commit also adds the correct messages for --verbose mode:

$ cp -r --parents --verbose a/b/c d
a -> d/a
a/b -> d/a/b
'a/b/c' -> 'd/a/b/c'

Fixes #3332.

jfinkels avatar Sep 03 '22 02:09 jfinkels

Okay there are some WIndows issues I need to resolve, but there is another failure reported in the GNU test suite that I want to explain.

The test case tests/cp/src-base-dot.sh claims to verify that

mkdir x y
cd y
cp --verbose -ab ../x/. .

succeeds, prints nothing to stdout, and is a no-op. However, it doesn't actually verify that the operation is a no-op, it only verifies that --verbose prints nothing. It just assumes that the directory x does not get copied into the directory y.

On the main branch, uutils cp will cause the directory x to be copied into the directory y, and nothing will be printed by --verbose (this is incorrect behavior). On this new branch, uutils cp will cause the directory x to be copied into the directory y but now --verbose will print the message ../x/. -> ./x (this is still incorrect behavior).

So the tests/cp/src-base-dot.sh test case was incorrectly passing on the main branch, and now it is correctly marked as a failure.

jfinkels avatar Sep 03 '22 03:09 jfinkels

nice: Warning: Congrats! The gnu test tests/cp/cp-parents is no longer ERROR!

sylvestre avatar Sep 03 '22 10:09 sylvestre

Did you see Error: GNU test failed: tests/cp/src-base-dot. tests/cp/src-base-dot is passing on 'main'. Maybe you have to rebase?

sylvestre avatar Sep 18 '22 19:09 sylvestre

Did you see Error: GNU test failed: tests/cp/src-base-dot. tests/cp/src-base-dot is passing on 'main'. Maybe you have to rebase?

Yes, it is an expected failure. The explanation is in my comment above https://github.com/uutils/coreutils/pull/3894#issuecomment-1236041009 and I created a new issue for that here https://github.com/uutils/coreutils/issues/3897

jfinkels avatar Sep 21 '22 20:09 jfinkels

sorry about that :(

sylvestre avatar Sep 21 '22 20:09 sylvestre

Seems that it broke a few tests ?


Error: GNU test failed: tests/cp/cp-i. tests/cp/cp-i is passing on 'main'. Maybe you have to rebase?
Error: GNU test failed: tests/cp/src-base-dot. tests/cp/src-base-dot is passing on 'main'. Maybe you have to rebase?

sylvestre avatar Oct 10 '22 06:10 sylvestre

tests/cp/src-base-dot is an expected new failure, see my comments above. However, tests/cp/cp-i does seem to be an unexpected new failure, so I'll fix that.

jfinkels avatar Oct 10 '22 14:10 jfinkels

I'm going to mark this as a draft pull request because there's still some weird behaviors of GNU cp that I haven't quite figure out yet. Specifically, I need to figure out how to get the quoting behavior for cp -v to work in both the cp-i.sh test case and the cp-parents.sh case.

jfinkels avatar Oct 10 '22 17:10 jfinkels

Okay, this is ready for review again.

jfinkels avatar Oct 11 '22 02:10 jfinkels

I'm going to close this and come back with a pull request that doesn't attempt to implement the --verbose behavior.

jfinkels avatar Oct 23 '22 04:10 jfinkels