mirror of
https://github.com/containers/podman.git
synced 2025-06-20 17:13:43 +08:00
Merge pull request #6601 from zhangguanzhang/podman-cp-dir
fix podman cp can create an extra directory when the source is the container's root directory
This commit is contained in:
@ -296,4 +296,42 @@ var _ = Describe("Podman cp", func() {
|
||||
|
||||
os.Remove("testfile1")
|
||||
})
|
||||
It("podman cp the root directory from the ctr to an existing directory on the host ", func() {
|
||||
imgName := "test-cp-root-dir:latest"
|
||||
DockerfileName := "Dockerfile.test-cp-root-dir"
|
||||
ctrName := "test-container-cp-root"
|
||||
|
||||
session := podmanTest.PodmanNoCache([]string{"build", "-f", "build/" + DockerfileName, "-t", imgName, "build/"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
testDirPath := filepath.Join(podmanTest.RunRoot, "TestDirForCp")
|
||||
|
||||
session = podmanTest.Podman([]string{"create", "--name", ctrName, imgName, "dummy"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
err := os.Mkdir(testDirPath, 0755)
|
||||
Expect(err).To(BeNil())
|
||||
defer os.RemoveAll(testDirPath)
|
||||
|
||||
// Copy the root directory of the container to an existing directory
|
||||
session = podmanTest.Podman([]string{"cp", ctrName + ":/", testDirPath})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// The file should be in the directory,
|
||||
// not one layer too much of the directory called merged
|
||||
checkFile := filepath.Join(testDirPath, DockerfileName)
|
||||
_, err = os.Stat(checkFile)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
session = podmanTest.Podman([]string{"container", "rm", ctrName})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.PodmanNoCache([]string{"rmi", "-f", imgName})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user