diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-06-24 23:49:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-24 23:49:57 +0200 |
commit | 394e12aa656ed3d9cc0afef48f1315fff5ed5db3 (patch) | |
tree | 0a8942ee153e22115cd637f8fafde9b514293e89 /cmd | |
parent | a1a4a75abee2c381483a218e1660621ee416ef7c (diff) | |
parent | c962d214e6156bd4d89e0eb20246549eca272ba7 (diff) | |
download | podman-394e12aa656ed3d9cc0afef48f1315fff5ed5db3.tar.gz podman-394e12aa656ed3d9cc0afef48f1315fff5ed5db3.tar.bz2 podman-394e12aa656ed3d9cc0afef48f1315fff5ed5db3.zip |
Merge pull request #3391 from QiWang19/cp_file
fix bug creats directory copying file
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/cp.go | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/cmd/podman/cp.go b/cmd/podman/cp.go index a9418e6e0..efe343bfd 100644 --- a/cmd/podman/cp.go +++ b/cmd/podman/cp.go @@ -326,20 +326,6 @@ func copy(src, destPath, dest string, idMappingOpts storage.IDMappingOptions, ch } return nil } - if !archive.IsArchivePath(srcPath) { - // This srcPath is a file, and either it's not an - // archive, or we don't care whether or not it's an - // archive. - destfi, err := os.Stat(destPath) - if err != nil { - if !os.IsNotExist(err) { - return errors.Wrapf(err, "failed to get stat of dest path %s", destPath) - } - } - if destfi != nil && destfi.IsDir() { - destPath = filepath.Join(destPath, filepath.Base(srcPath)) - } - } if extract { // We're extracting an archive into the destination directory. @@ -350,9 +336,16 @@ func copy(src, destPath, dest string, idMappingOpts storage.IDMappingOptions, ch return nil } - if destDirIsExist || strings.HasSuffix(dest, string(os.PathSeparator)) { + destfi, err := os.Stat(destPath) + if err != nil { + if !os.IsNotExist(err) { + return errors.Wrapf(err, "failed to get stat of dest path %s", destPath) + } + } + if destfi != nil && destfi.IsDir() { destPath = filepath.Join(destPath, filepath.Base(srcPath)) } + // Copy the file, preserving attributes. logrus.Debugf("copying %q to %q", srcPath, destPath) if err = copyFileWithTar(srcPath, destPath); err != nil { |