From 9d293bd2de60f101b3712d2e099584221516776d Mon Sep 17 00:00:00 2001 From: zhangguanzhang Date: Sun, 14 Jun 2020 19:45:52 +0800 Subject: fix podman cp can create an extra directory level Signed-off-by: zhangguanzhang --- pkg/domain/infra/abi/cp.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'pkg') 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) -- cgit v1.2.3-54-g00ecf