aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-04-08 07:48:54 -0700
committerGitHub <noreply@github.com>2019-04-08 07:48:54 -0700
commit7f8e9bd54c7a1c46ea19b58296f6629d55988e0d (patch)
tree72242231e3fda573a840d726b936d36710a0fa10 /cmd
parent995c5d854f5fbceae61cfe3fa81ee47924539055 (diff)
parent84620021b09778d64d7516e693301d0a08f082c9 (diff)
downloadpodman-7f8e9bd54c7a1c46ea19b58296f6629d55988e0d.tar.gz
podman-7f8e9bd54c7a1c46ea19b58296f6629d55988e0d.tar.bz2
podman-7f8e9bd54c7a1c46ea19b58296f6629d55988e0d.zip
Merge pull request #2845 from QiWang19/cpdir
fix bug podman cp directory
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/cp.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/cmd/podman/cp.go b/cmd/podman/cp.go
index a0dd46260..7dee37287 100644
--- a/cmd/podman/cp.go
+++ b/cmd/podman/cp.go
@@ -1,6 +1,7 @@
package main
import (
+ "fmt"
"os"
"path/filepath"
"strings"
@@ -207,6 +208,11 @@ func copy(src, destPath, dest string, idMappingOpts storage.IDMappingOptions, ch
if !srcfi.IsDir() && !strings.HasSuffix(dest, string(os.PathSeparator)) {
destdir = filepath.Dir(destPath)
}
+ _, err = os.Stat(destdir)
+ if err != nil && !os.IsNotExist(err) {
+ return errors.Wrapf(err, "error checking directory %q", destdir)
+ }
+ destDirIsExist := (err == nil)
if err = os.MkdirAll(destdir, 0755); err != nil {
return errors.Wrapf(err, "error creating directory %q", destdir)
}
@@ -219,6 +225,9 @@ func copy(src, destPath, dest string, idMappingOpts storage.IDMappingOptions, ch
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))
+ }
if err = copyWithTar(srcPath, destPath); err != nil {
return errors.Wrapf(err, "error copying %q to %q", srcPath, dest)
}