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

use internal copy rather than tar for copy fix #6003 #6279

Conversation

joequant
Copy link

This patch uses internal copy to copy containers rather than
tar. The problem with tar is that it does not copy symlinks pointing
outside of the volume.

This is a very tricky patch to get right because you have to get the
ownerships and permissions right as well as handle symlinks
correctly. Off the shelf copy trees don't work because they dont
have the right combination of options to do the right thing.

This patch uses internal copy to copy containers rather than
tar.  The problem with tar is that it does not copy symlinks pointing
outside of the volume.
@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: joequant
To complete the pull request process, please assign giuseppe
You can assign the PR to them by writing /assign @giuseppe 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

@openshift-ci-robot
Copy link
Collaborator

Hi @joequant. Thanks for your PR.

I'm waiting for a containers member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 19, 2020
@haircommander
Copy link
Collaborator

/ok-to-test

@openshift-ci-robot openshift-ci-robot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 19, 2020
@TomSweeneyRedHat
Copy link
Member

@nalind PTAL


for _, entry := range entries {
srcPath := filepath.Join(src, entry.Name())
dstPath := filepath.Join(dst, entry.Name())
Copy link
Member

Choose a reason for hiding this comment

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

I think you want to user securejoin for these

Comment on lines +1440 to +1490
func (c *Container) copyWithOwnerAndPerms(src, dst string) error {
if samefile(src, dst) {
return &CopyError{src, dst}
}

srcStat, err := os.Lstat(src)
if err != nil {
return err
} else if specialfile(srcStat) {
return &CopyError{src, dst}
}

if dstInfo, err := os.Stat(dst); err == nil && dstInfo.Mode().IsDir() {
dst = filepath.Join(dst, filepath.Base(src))
} else if err != nil && !os.IsNotExist(err) {
return err
}

if IsSymlink(srcStat) {
if srcLink, err := os.Readlink(src); err != nil {
return err
} else if err := os.Symlink(srcLink, dst); err != nil {
return err
}
}

// Do the actual copy
fsrc, err := os.Open(src)
if err != nil {
return err
}
defer fsrc.Close()

fdst, err := os.Create(dst)
if err != nil {
return err
}
defer fdst.Close()

if size, err := io.Copy(fdst, fsrc); err != nil {
return err
} else if size != srcStat.Size() {
return fmt.Errorf("%s: %d/%d copied", src, size, srcStat.Size())
}

if err = c.copyOwnerAndPerms(src, dst); err != nil {
return err
}

return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

could we use CopyFile from github.com/mrunalp/fileutils here?

Copy link
Member

Choose a reason for hiding this comment

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

The tar-based logic would have attempted to preserve timestamps and xattrs on items it copied, and made an effort to preserve hard links among multiple items being copied. If we don't want to lose those features (whether podman wants to keep those things could well be different than the previous implementation), they'll need to be added back here.

Copy link
Member

Choose a reason for hiding this comment

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

Xattrs are likely important. I don't know if timestamps are; need to check.

Copy link
Member

Choose a reason for hiding this comment

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

Hardlinks also, to save on size.

return (fi.Mode() & os.ModeNamedPipe) == os.ModeNamedPipe
}

func IsSymlink(fi os.FileInfo) bool {
Copy link
Member

Choose a reason for hiding this comment

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

This function looks like it doesn't need to be exported.

@rhatdan
Copy link
Member

rhatdan commented Jun 9, 2020

@joequant Still working on this, needs a rebase and some comments addressed.

@vrothberg
Copy link
Member

Friendly ping.

@rhatdan
Copy link
Member

rhatdan commented Jun 23, 2020

@mheon If you are going to work on rewriting copy, you might want to take this over.

@github-actions
Copy link

A friendly reminder that this PR had no activity for 30 days.

@rhatdan
Copy link
Member

rhatdan commented Jul 24, 2020

The Copy rewrite is continuing on Buildah and is progressing, I think we should close this and work on the new Copy once it merges into Buildah.

@rhatdan rhatdan closed this Jul 24, 2020
@joequant
Copy link
Author

joequant commented Aug 9, 2020

Thanks. Also any ETA for when the changes will get merged in? I'm using docker and would like to migrate over to podman.

@joequant
Copy link
Author

joequant commented Aug 9, 2020

Can you link the issue that tracks this on buildah? Thanks.

@rhatdan
Copy link
Member

rhatdan commented Aug 10, 2020

containers/buildah#2476

@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
locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. ok-to-test stale-pr
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants