mirror of
https://github.com/containers/podman.git
synced 2025-05-31 07:27:13 +08:00
Merge pull request #3194 from QiWang19/cptar
fix bug dest path of copying tar
This commit is contained in:
@ -272,6 +272,10 @@ func copy(src, destPath, dest string, idMappingOpts storage.IDMappingOptions, ch
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if destDirIsExist || strings.HasSuffix(dest, string(os.PathSeparator)) {
|
||||
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 {
|
||||
|
@ -131,4 +131,31 @@ var _ = Describe("Podman cp", func() {
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
})
|
||||
|
||||
It("podman cp tar", func() {
|
||||
path, err := os.Getwd()
|
||||
Expect(err).To(BeNil())
|
||||
testDirPath := filepath.Join(path, "TestDir")
|
||||
err = os.Mkdir(testDirPath, 0777)
|
||||
Expect(err).To(BeNil())
|
||||
cmd := exec.Command("tar", "-cvf", "file.tar", testDirPath)
|
||||
_, err = cmd.Output()
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
session := podmanTest.Podman([]string{"create", "--name", "testctr", ALPINE, "ls", "-l", "foo"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"cp", "file.tar", "testctr:/foo/"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"start", "-a", "testctr"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(session.OutputToString()).To(ContainSubstring("file.tar"))
|
||||
|
||||
os.Remove("file.tar")
|
||||
os.RemoveAll(testDirPath)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user