-
Notifications
You must be signed in to change notification settings - Fork 2.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
fix cp none exists dest path ends with '/' #4101
Conversation
Don't forget to update |
cmd/podman/cp.go
Outdated
@@ -329,6 +329,9 @@ func copy(src, destPath, dest string, idMappingOpts storage.IDMappingOptions, ch | |||
|
|||
destfi, err := os.Stat(destPath) | |||
if err != nil { | |||
if strings.HasSuffix(dest, string(os.PathSeparator)) { |
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.
looks like the same error message, can you do a single if with an "or" statement?
@QiWang19 some of the tests aren't too happy. |
8e5406a
to
bc106fe
Compare
bc106fe
to
643a25c
Compare
8a94a91
to
23c3962
Compare
test/system/065-cp.bats
Outdated
@@ -149,7 +149,7 @@ load helpers | |||
is "$output" "" "output from podman cp 1" | |||
|
|||
run_podman cp --pause=false $srcdir/$rand_filename2 cpcontainer:/tmp/d2/x/ | |||
is "$output" "" "output from podman cp 3" | |||
is "$output" "Error: failed to get stat of dest path .*stat.* no such file or directory" "cp returns error no such file or directory" |
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.
You need to change the expected exit status, e.g.:
run_podman 12345 cp --pause ...
...where 12345 is the expected exit status of the cp command (probably 1, but may be something else, see test logs)
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.
@edsantiago thanks. 🙂 Do I still need keep this current change?
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 check for "Error"? Yes.
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.
:ok
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.
Since changes are needed, please also change the test description:
- "cp returns error no such file or directory"
+ "cp will not create nonexistent destination directory"
23c3962
to
9e5f698
Compare
9e5f698
to
d12be35
Compare
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.
Sorry for replying so late; there was too much churn yesterday.
@@ -148,8 +148,8 @@ load helpers | |||
run_podman cp --pause=false $srcdir/$rand_filename1 cpcontainer:/tmp/d1/x |
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 line immediately above this one, #147, is a comment that is now incorrect. Please change it:
- # Note that the second has a trailing slash; this will trigger mkdir
+ # Note that the second has a trailing slash, implying a directory.
+ # Since that destination directory doesn't exist, the cp will fail
Sorry for not catching this sooner.
test/system/065-cp.bats
Outdated
@@ -149,7 +149,7 @@ load helpers | |||
is "$output" "" "output from podman cp 1" | |||
|
|||
run_podman cp --pause=false $srcdir/$rand_filename2 cpcontainer:/tmp/d2/x/ | |||
is "$output" "" "output from podman cp 3" | |||
is "$output" "Error: failed to get stat of dest path .*stat.* no such file or directory" "cp returns error no such file or directory" |
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.
Since changes are needed, please also change the test description:
- "cp returns error no such file or directory"
+ "cp will not create nonexistent destination directory"
test/system/065-cp.bats
Outdated
@@ -163,8 +163,8 @@ load helpers | |||
|
|||
# In the second case, podman creates a directory nonesuch2, then | |||
# creates a file with the same name as the input file. THIS IS WEIRD! |
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.
Please also fix these comments.
test/system/065-cp.bats
Outdated
@@ -163,8 +163,8 @@ load helpers | |||
|
|||
# In the second case, podman creates a directory nonesuch2, then | |||
# creates a file with the same name as the input file. THIS IS WEIRD! | |||
run_podman exec cpcontainer cat /tmp/nonesuch2/$rand_filename2 | |||
is "$output" "$rand_content2" "cp creates destination dir and file" | |||
run_podman 1 exec cpcontainer cat /tmp/nonesuch2/$rand_filename2 |
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.
Since podman behavior has changed, this is no longer a great test: it simply checks that the destination file doesn't exist - but it is conceivable (albeit improbable) that podman created the destination directory before exiting. That would be very bad. A much better test would now be:
# cp into nonexistent directory should not mkdir said directory
run_podman 1 exec cpcontainer test -e /tmp/nonesuch2
This test is much more useful.
test/system/065-cp.bats
Outdated
@@ -221,4 +221,4 @@ function teardown() { | |||
basic_teardown | |||
} | |||
|
|||
# vim: filetype=sh | |||
# vim: filetype=sh |
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.
Please fix. (You removed the closing newline. Please add it back).
close containers#3894 This patch let podman cp return 'no such file or directory' error if DEST_PATH does not exist and ends with / when copying file. Signed-off-by: Qi Wang <qiwan@redhat.com>
d12be35
to
0144c37
Compare
Code changes LGTM, I'll let you and @edsantiago work through the testing comments. Some of the tests aren't happy ATM. |
Latest change (0144c37) LGTM. @TomSweeneyRedHat the CI "failures" are the same as yesterday, i.e. false alarms |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: edsantiago, mheon, QiWang19 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Needs lgtm label. 🏷️ |
/lgtm |
close #3894
This patch will let podman cp return 'no such file or directory' error if DEST_PATH does not exist and ends with / when copying file.
Signed-off-by: Qi Wang qiwan@redhat.com