From 07637f101ba5f775d4ea22385e447c4e9c64be84 Mon Sep 17 00:00:00 2001 From: Lokesh Mandvekar Date: Wed, 4 Feb 2026 16:31:08 +0530 Subject: [PATCH] test/e2e: close and remove temp file before cp in cp_test Close the temporary destination file and remove it before copying to avoid issues with copying to an existing open file. Store the filename in a variable for reuse and defer cleanup. Signed-off-by: Lokesh Mandvekar Signed-off-by: Chris Evich --- test/e2e/cp_test.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/test/e2e/cp_test.go b/test/e2e/cp_test.go index d7688f5b44..edf2ae238b 100644 --- a/test/e2e/cp_test.go +++ b/test/e2e/cp_test.go @@ -72,12 +72,14 @@ var _ = Describe("Podman cp", func() { // Copy FROM the container. - destFile, err := ioutil.TempFile("", "") - Expect(err).To(BeNil()) - defer destFile.Close() - defer os.Remove(destFile.Name()) + destFile, err := os.CreateTemp("", "") + Expect(err).ToNot(HaveOccurred()) + destFileName := destFile.Name() + destFile.Close() + os.Remove(destFileName) + defer os.Remove(destFileName) - session = podmanTest.Podman([]string{"cp", name + ":foo", destFile.Name()}) + session = podmanTest.Podman([]string{"cp", name + ":foo", destFileName}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) @@ -86,8 +88,8 @@ var _ = Describe("Podman cp", func() { Expect(session).Should(Exit(0)) // Now make sure the content matches. - roundtripContent, err := ioutil.ReadFile(destFile.Name()) - Expect(err).To(BeNil()) + roundtripContent, err := os.ReadFile(destFileName) + Expect(err).ToNot(HaveOccurred()) Expect(roundtripContent).To(Equal(originalContent)) }) @@ -121,18 +123,20 @@ var _ = Describe("Podman cp", func() { // Copy FROM the container. - destFile, err := ioutil.TempFile("", "") - Expect(err).To(BeNil()) - defer destFile.Close() - defer os.Remove(destFile.Name()) + destFile, err := os.CreateTemp("", "") + Expect(err).ToNot(HaveOccurred()) + destFileName := destFile.Name() + destFile.Close() + os.Remove(destFileName) + defer os.Remove(destFileName) - session = podmanTest.Podman([]string{"cp", name + ":foo", destFile.Name()}) + session = podmanTest.Podman([]string{"cp", name + ":foo", destFileName}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) // Now make sure the content matches. - roundtripContent, err := ioutil.ReadFile(destFile.Name()) - Expect(err).To(BeNil()) + roundtripContent, err := os.ReadFile(destFileName) + Expect(err).ToNot(HaveOccurred()) Expect(roundtripContent).To(Equal(originalContent)) })