-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
support container to container copy #10728
Conversation
Signed-off-by: Mehul Arora <[email protected]>
You will need to add tests for this. @vrothberg PTAL |
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.
Thanks!
Yes, we need a lot of tests for this one. Look at the tests in https://github.com/containers/podman/blob/master/test/system/065-cp.bats which have a decent coverage of all corner cases and the basic copy functionality.
cmd/podman/containers/cp.go
Outdated
|
||
toContainerInfo, err := registry.ContainerEngine().ContainerStat(registry.GetContext(), toContainer, destPath) | ||
if err != nil { | ||
return errors.Wrapf(err, "%q could not be found on container %s", destPath, toContainer) |
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.
That should not be an error per-se. If I do cp 1:/foo.txt 2:/foo.txt
then "foo.txt" should be created at the destination. Have a look at the copy functions above for the wiring.
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 didn't understand why we are checking for this condition here: https://github.com/containers/podman/blob/master/cmd/podman/containers/cp.go#L266
If possible, could you please give an example
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.
If we do a cp 1:/dir 2:/tmp/foo/
foo
must exist. If we do a cp 1:/dir 2:/tmp/foo
foo
would be created if it doesn't exist.
The condition enforces that rule. The podman-cp
man pages mention these rules.
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.
Thanks for adding those comments btw, they are very helpful! I will work on the missing cases soon
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.
Happy to help! Feel free to ping me here on IRC at any time. I am reachable during regular CEST working hours.
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.
@vrothberg a bit confused about git, how do I get the changes you made to the branch on my fork?
would it be like checking out to main and then pulling the changes and checking out to my branch c2c-copy
and then merging main to my branch?
wouldn't that mean losing the changes I made?
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.
What I usually do is the following (upstream
is the remote branch pointing to github.com/containers/podman
):
$ git remote update
$ git pull --rebase upstream master
Note that while rebasing you may have to resolve merge conflicts.
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.
been on this for hours now, cant seem to figure this. I was able to update the c2c-copy branch to the recent changes on podman but the changes you made yesterday don't reflect? even git log shows your merged PR
And surprisingly, I did not get any merge conflicts?
I think I might have to just re-add those changes and continue
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.
Nevermind, I figured it out. Didn't have to do anything manually
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.
@vrothberg so I am not sure how we will go about renaming files for container-container copy in a case like:
podman container cp distracted_tesla:ok.txt pedantic_hertz:ok.txt
In host->container or container->host I can see that the buildah copier package is handling that for us but how do we do this for this case?
I was able to fix the segmentation fault
[mehul@fedora bin]$ ./podman cp c1:file.txt c2:/skbxlswx
[mehul@fedora bin]$ ./podman exec c2 /bin/sh -c "ls"
bin
dev
etc
file.txt
home
proc
root
run
sys
tmp
usr
var
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: infiniteregrets The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Mehul Arora <[email protected]>
return errors.Wrapf(err, "%q could not be found on container %s", sourcePath, fromContainer) | ||
} | ||
|
||
var toContainerBaseName string |
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.
can you change to toContainerBaseName := ""
removes an unnecessary line.
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.
Also, I am seeing you are getting an ineffectual assignment error here. Where are you using toContainerBaseName
after setting it?
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.
can you change to toContainerBaseName := "" removes an unnecessary line.
sure, will make the changes once I figure everything out
Also, I am seeing you are getting an ineffectual assignment error here. Where are you using toContainerBaseName after setting it?
I am not completely sure tbh, I had to do _ = toContainerBaseName to get rid of that unused variable error
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 @infiniteregrets you're getting that error because you set the base name and never actually use it. the _ =
is just a clever way to trick golang. You should use that name somewhere in your copy 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.
@cdoern I am using it?
if toContainerInfo != nil {
toContainerBaseName = filepath.Base(toContainerInfo.LinkTarget)
} else {
toContainerBaseName = filepath.Base(destPath)
}
This looks like a shadowing issue? Im not sure but I'll try to figure it. Thanks!
} | ||
reader, writer := io.Pipe() | ||
|
||
fromContainerCopy := func() error { |
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.
potentially could consolidate toContainerCopy
and fromContainercopy
into a function you call twice that takes specific parameters. Seems slightly redundant to have nearly identical code twice.
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 might be some changes to the functions, so depending on what the final outcome looks like i'll refactor the code
Please create a new PR against the new |
This would fix #7370. I haven't done anything yet, but this seems to work:
I am missing some cases where a file to file copy would occur or if the path is a symbolic link and read/write should be recursive. Once I am sure about how everything works I will fix that. I think checking whether a path exists on a container and getting containerinfo can be speeded up by doing so in a separate thread
I am unable to test much locally because my laptop gets really hot and laggy, so I am just pushing this here.
Thanks!
Signed-off-by: Mehul Arora [email protected]