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

support container to container copy #10728

Closed
wants to merge 3 commits into from
Closed

support container to container copy #10728

wants to merge 3 commits into from

Conversation

infiniteregrets
Copy link

This would fix #7370. I haven't done anything yet, but this seems to work:

[mehul@fedora bin]$ ./podman container exec 59aef1582431 /bin/sh -c 'mkdir test'
[mehul@fedora bin]$ ./podman container cp ffae1af127e0:/tmp 59aef1582431:/test
[mehul@fedora bin]$ ./podman container exec 59aef1582431 /bin/sh -c 'cd test && ls'
tmp

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]

@rhatdan
Copy link
Member

rhatdan commented Jun 20, 2021

You will need to add tests for this.

@vrothberg PTAL

Copy link
Member

@vrothberg vrothberg left a 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.


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

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.

Copy link
Author

@infiniteregrets infiniteregrets Jun 22, 2021

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

Copy link
Member

@vrothberg vrothberg Jun 22, 2021

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.

Copy link
Author

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

Copy link
Member

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.

Copy link
Author

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?

Copy link
Member

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.

Copy link
Author

@infiniteregrets infiniteregrets Jun 25, 2021

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

Copy link
Author

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

Copy link
Author

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

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 25, 2021

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: infiniteregrets
To complete the pull request process, please assign saschagrunert after the PR has been reviewed.
You can assign the PR to them by writing /assign @saschagrunert in a comment when ready.

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

Signed-off-by: Mehul Arora <[email protected]>
return errors.Wrapf(err, "%q could not be found on container %s", sourcePath, fromContainer)
}

var toContainerBaseName string
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Author

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

Copy link
Contributor

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.

Copy link
Author

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 {
Copy link
Contributor

@cdoern cdoern Jun 25, 2021

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.

Copy link
Author

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

@rhatdan rhatdan closed this Jun 30, 2021
@rhatdan rhatdan deleted the branch containers:master June 30, 2021 15:09
@vrothberg
Copy link
Member

Please create a new PR against the new main branch. @rhatdan, the master->main migration closes on PRs against master.

@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 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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.

support container-to-container copy
4 participants