summaryrefslogtreecommitdiff
path: root/pkg/domain
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-06-15 13:20:35 -0400
committerGitHub <noreply@github.com>2020-06-15 13:20:35 -0400
commit5a82a559c6b58833df8fc02a589e9f349a053e16 (patch)
treedcb6288ce8fafc73ebf5e6244ddce47462a33892 /pkg/domain
parent6e0cf678745a1dff267b800fd3490e6889b473ec (diff)
parent9d293bd2de60f101b3712d2e099584221516776d (diff)
downloadpodman-5a82a559c6b58833df8fc02a589e9f349a053e16.tar.gz
podman-5a82a559c6b58833df8fc02a589e9f349a053e16.tar.bz2
podman-5a82a559c6b58833df8fc02a589e9f349a053e16.zip
Merge pull request #6601 from zhangguanzhang/podman-cp-dir
fix podman cp can create an extra directory when the source is the container's root directory
Diffstat (limited to 'pkg/domain')
-rw-r--r--pkg/domain/infra/abi/cp.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/pkg/domain/infra/abi/cp.go b/pkg/domain/infra/abi/cp.go
index 7567d5a70..82b07e2e1 100644
--- a/pkg/domain/infra/abi/cp.go
+++ b/pkg/domain/infra/abi/cp.go
@@ -260,7 +260,19 @@ func containerCopy(srcPath, destPath, src, dest string, idMappingOpts storage.ID
if srcfi.IsDir() {
logrus.Debugf("copying %q to %q", srcPath+string(os.PathSeparator)+"*", dest+string(os.PathSeparator)+"*")
if destDirIsExist && !strings.HasSuffix(src, fmt.Sprintf("%s.", string(os.PathSeparator))) {
- destPath = filepath.Join(destPath, filepath.Base(srcPath))
+ srcPathBase := filepath.Base(srcPath)
+ if !isFromHostToCtr {
+ pathArr := strings.SplitN(src, ":", 2)
+ if len(pathArr) != 2 {
+ return errors.Errorf("invalid arguments %s, you must specify source path", src)
+ }
+ if pathArr[1] == "/" {
+ // If `srcPath` is the root directory of the container,
+ // `srcPath` will be `.../${sha256_ID}/merged/`, so do not join it
+ srcPathBase = ""
+ }
+ }
+ destPath = filepath.Join(destPath, srcPathBase)
}
if err = copyWithTar(srcPath, destPath); err != nil {
return errors.Wrapf(err, "error copying %q to %q", srcPath, dest)