mirror of
https://github.com/containers/podman.git
synced 2025-06-17 23:20:59 +08:00
Merge pull request #3391 from QiWang19/cp_file
fix bug creats directory copying file
This commit is contained in:
@ -326,20 +326,6 @@ func copy(src, destPath, dest string, idMappingOpts storage.IDMappingOptions, ch
|
|||||||
}
|
}
|
||||||
return nil
|
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 {
|
if extract {
|
||||||
// We're extracting an archive into the destination directory.
|
// 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
|
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))
|
destPath = filepath.Join(destPath, filepath.Base(srcPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the file, preserving attributes.
|
// Copy the file, preserving attributes.
|
||||||
logrus.Debugf("copying %q to %q", srcPath, destPath)
|
logrus.Debugf("copying %q to %q", srcPath, destPath)
|
||||||
if err = copyFileWithTar(srcPath, destPath); err != nil {
|
if err = copyFileWithTar(srcPath, destPath); err != nil {
|
||||||
|
@ -58,6 +58,10 @@ var _ = Describe("Podman cp", func() {
|
|||||||
session = podmanTest.Podman([]string{"cp", name + ":foo", dstPath})
|
session = podmanTest.Podman([]string{"cp", name + ":foo", dstPath})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"start", name})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman cp file to dir", func() {
|
It("podman cp file to dir", func() {
|
||||||
|
Reference in New Issue
Block a user