summaryrefslogtreecommitdiff
path: root/pkg/domain/infra/abi/cp.go
diff options
context:
space:
mode:
authorzhangguanzhang <zhangguanzhang@qq.com>2020-06-14 19:45:52 +0800
committerzhangguanzhang <zhangguanzhang@qq.com>2020-06-15 23:56:45 +0800
commit9d293bd2de60f101b3712d2e099584221516776d (patch)
treecf429356c7b7b9420f3608b2eb38d7f6994c66e3 /pkg/domain/infra/abi/cp.go
parent3218736cff4b718b8fe855759687cb66f19d6e1e (diff)
downloadpodman-9d293bd2de60f101b3712d2e099584221516776d.tar.gz
podman-9d293bd2de60f101b3712d2e099584221516776d.tar.bz2
podman-9d293bd2de60f101b3712d2e099584221516776d.zip
fix podman cp can create an extra directory level
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
Diffstat (limited to 'pkg/domain/infra/abi/cp.go')
-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 9fc1e3bee..542813394 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)