-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: correctly copy ancestor dirs in --parents mode #3894
Conversation
6786fa0
to
89888d5
Compare
.stdout_is("a -> d/a\na/b -> d/a/b\n'a/b/c' -> 'd/a/b/c'\n"); | ||
assert!(at.dir_exists("d/a/b/c")); | ||
} | ||
|
||
#[test] | ||
#[ignore = "issue #3332"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two tests below here that are currently ignored. They are marked as "issue #3332", but they are actually covering use cases that are slightly different than the one originally reported in that issue. Because they are slightly different use cases (and completely different code paths), I decided not to try to resolve them in this pull request.
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
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 On the main branch, uutils cp will cause the directory So the |
nice: |
4e70a21
to
6a18e00
Compare
6a18e00
to
a035adc
Compare
Did you see |
b8328f6
to
f61b123
Compare
Yes, it is an expected failure. The explanation is in my comment above #3894 (comment) and I created a new issue for that here #3897 |
sorry about that :( |
f392685
to
47c5bba
Compare
Seems that it broke a few tests ?
|
|
824ed12
to
15e9566
Compare
Before this commit, `cp -a` would terminate with a non-zero status code on Windows because there are no extended attributes (xattr) to copy. However, the GNU documentation for cp states > Try to preserve SELinux security context and extended attributes > (xattr), but ignore any failure to do that and print no > corresponding diagnostic. so it seems reasonable to do nothing instead of exiting with an error in this case.
15e9566
to
2d84ef3
Compare
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 |
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 uutils#3332.
2d84ef3
to
ada7064
Compare
Okay, this is ready for review again. |
ancestors.push(p); | ||
} | ||
for p in ancestors.iter().rev().skip(1) { | ||
println!("{} -> {}", p.display(), target.join(p).display()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ancestors are printed without quotes, so using context_for()
is not appropriate here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a good idea to add that info as a comment in the code!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused, because the messages don't show up for me with this PR:
❯ touch x/y/z/foo
❯ mkdir bar
❯ cargo run --quiet -- cp --parents --verbose x/y/z/foo bar
'x/y/z/foo' -> 'test2/x/y/z/foo'
❯ rm -r bar/*
❯ cp --parents --verbose x/y/z/foo bar
x -> bar/x
x/y -> bar/x/y
x/y/z -> bar/x/y/z
'x/y/z/foo' -> 'bar/x/y/z/foo'
Also I think this PR does not have the right messages if a part of the subdirectories already. For example, below there is no line x -> bar/x
:
❯ mkdir bar/x
❯ cp --parents --verbose x/y/z/foo bar
x/y -> bar/x/y
x/y/z -> bar/x/y/z
'x/y/z/foo' -> 'bar/x/y/z/foo'
(I might be wrong because I couldn't trigger the messages)
let mut ancestors = vec![]; | ||
for p in parent.ancestors() { | ||
ancestors.push(p); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work?
let mut ancestors = vec![]; | |
for p in parent.ancestors() { | |
ancestors.push(p); | |
} | |
let ancestors: Vec<_> = parent.ancestors().collect(); |
I'm going to close this and come back with a pull request that doesn't attempt to implement the |
Fix a bug where
cp
failed to copy ancestor directories when usingthe
--parents
option. For example, before this commit:After this commit
This commit also adds the correct messages for
--verbose
mode:Fixes #3332.