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

fix cp none exists dest path ends with '/' #4101

Merged
merged 1 commit into from
Sep 25, 2019

Conversation

QiWang19
Copy link
Collaborator

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.

$ podman run -d --name cpc alpine sh -c 'sleep 999'
$ podman exec cpc sh -c 'mkdir /tmp/d1;ln -s /tmp/nonesuch1 /tmp/d1/x'
$ podman exec cpc sh -c 'mkdir /tmp/d2;ln -s /tmp/nonesuch2 /tmp/d2/x'
$ podman exec cpc sh -c 'mkdir /tmp/d3'
$ podman exec cpc ls -lR /tmp
/tmp:
total 12
drwxr-xr-x    2 root     root          4096 Sep 24 14:45 d1
drwxr-xr-x    2 root     root          4096 Sep 24 14:45 d2
drwxr-xr-x    2 root     root          4096 Sep 24 14:45 d3

/tmp/d1:
total 0
lrwxrwxrwx    1 root     root            14 Sep 24 14:45 x -> /tmp/nonesuch1

/tmp/d2:
total 0
lrwxrwxrwx    1 root     root            14 Sep 24 14:45 x -> /tmp/nonesuch2

/tmp/d3:
total 0

$ podman cp /tmp/myfile cpc:/tmp/d1/x
$ podman cp /tmp/myfile cpc:/tmp/d2/x/
Error: failed to get stat of dest path /home/qiwan/.local/share/containers/storage/overlay/82311cd5e4e276073e44ad65eaeec65a048a3141d447d4b46393b1c3fac64168/merged/tmp/nonesuch2: stat /home/qiwan/.local/share/containers/storage/overlay/82311cd5e4e276073e44ad65eaeec65a048a3141d447d4b46393b1c3fac64168/merged/tmp/nonesuch2: no such file or directory
$ podman cp /tmp/myfile cpc:/tmp/d3/x
$ podman exec cpc ls -lR /tmp
/tmp:
total 16
drwxr-xr-x    2 root     root          4096 Sep 24 14:45 d1
drwxr-xr-x    2 root     root          4096 Sep 24 14:45 d2
drwxr-xr-x    2 root     root          4096 Sep 24 14:46 d3
-rw-rw-r--    1 root     root             3 Sep 24 14:07 nonesuch1

/tmp/d1:
total 0
lrwxrwxrwx    1 root     root            14 Sep 24 14:45 x -> /tmp/nonesuch1

/tmp/d2:
total 0
lrwxrwxrwx    1 root     root            14 Sep 24 14:45 x -> /tmp/nonesuch2

/tmp/d3:
total 4
-rw-rw-r--    1 root     root             3 Sep 24 14:07 x

Signed-off-by: Qi Wang qiwan@redhat.com

@QiWang19
Copy link
Collaborator Author

@TomSweeneyRedHat @edsantiago @mheon PTAL

@edsantiago
Copy link
Collaborator

Don't forget to update test/system/065-cp.bats

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)) {
Copy link
Member

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?

@TomSweeneyRedHat
Copy link
Member

@QiWang19 some of the tests aren't too happy.

@@ -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"
Copy link
Collaborator

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)

Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

:ok

Copy link
Collaborator

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"

@QiWang19
Copy link
Collaborator Author

@TomSweeneyRedHat @edsantiago @mheon PTAL

Copy link
Collaborator

@edsantiago edsantiago left a 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
Copy link
Collaborator

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.

@@ -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"
Copy link
Collaborator

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"

@@ -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!
Copy link
Collaborator

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.

@@ -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
Copy link
Collaborator

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.

@@ -221,4 +221,4 @@ function teardown() {
basic_teardown
}

# vim: filetype=sh
# vim: filetype=sh
Copy link
Collaborator

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>
@TomSweeneyRedHat
Copy link
Member

Code changes LGTM, I'll let you and @edsantiago work through the testing comments. Some of the tests aren't happy ATM.

@edsantiago
Copy link
Collaborator

Latest change (0144c37) LGTM.

@TomSweeneyRedHat the CI "failures" are the same as yesterday, i.e. false alarms

@mheon
Copy link
Member

mheon commented Sep 25, 2019

/approve
LGTM

@openshift-ci-robot
Copy link
Collaborator

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 25, 2019
@QiWang19
Copy link
Collaborator Author

Needs lgtm label. 🏷️

@mheon
Copy link
Member

mheon commented Sep 25, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 25, 2019
@openshift-merge-robot openshift-merge-robot merged commit 3ed265c into containers:master Sep 25, 2019
@QiWang19 QiWang19 deleted the nonexistdir branch June 26, 2020 15:10
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

podman cp: unexpected mkdir on symlink expansion
6 participants