From 8b340f4e5c01c610b7be6c30b17464f677d62e2e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 23 Dec 2024 13:22:56 +0100 Subject: [PATCH 1/2] TestRunCopyFromContainerToFilesystem: use Tar without options Just a minor cleanup; use archive.Tar as we're not using other options here. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit a8f83d5d99d2965dad971cbb8ed893924b4cd393) Signed-off-by: Sebastiaan van Stijn --- cli/command/container/cp_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/container/cp_test.go b/cli/command/container/cp_test.go index 6bec0275bdea..3c23113571ac 100644 --- a/cli/command/container/cp_test.go +++ b/cli/command/container/cp_test.go @@ -74,7 +74,7 @@ func TestRunCopyFromContainerToFilesystem(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ containerCopyFromFunc: func(ctr, srcPath string) (io.ReadCloser, container.PathStat, error) { assert.Check(t, is.Equal("container", ctr)) - readCloser, err := archive.TarWithOptions(destDir.Path(), &archive.TarOptions{}) + readCloser, err := archive.Tar(destDir.Path(), archive.Uncompressed) return readCloser, container.PathStat{}, err }, }) From 074820d7bbcd3b2f8bcceeb62ee626c342e44e5d Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 26 Dec 2024 16:14:45 -0800 Subject: [PATCH 2/2] Fix cp test to separate source and destination Currently the cp will tar from the same directory it will untar into simultaneously. There is a race between reading the file and truncating the file for write, however, the race will not show up with a large enough buffer on the tar side if buffered before the copy begins. Also removes the unnecessary deferred removal, the removal is handled by cleanup and respects the no cleanup env. Signed-off-by: Derek McGowan (cherry picked from commit 8c0cb30515d24b774e40b0a9bacceae56709a46c) Signed-off-by: Sebastiaan van Stijn --- cli/command/container/cp_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/command/container/cp_test.go b/cli/command/container/cp_test.go index 3c23113571ac..30de39adf467 100644 --- a/cli/command/container/cp_test.go +++ b/cli/command/container/cp_test.go @@ -67,14 +67,15 @@ func TestRunCopyFromContainerToStdout(t *testing.T) { } func TestRunCopyFromContainerToFilesystem(t *testing.T) { - destDir := fs.NewDir(t, "cp-test", + srcDir := fs.NewDir(t, "cp-test", fs.WithFile("file1", "content\n")) - defer destDir.Remove() + + destDir := fs.NewDir(t, "cp-test") cli := test.NewFakeCli(&fakeClient{ containerCopyFromFunc: func(ctr, srcPath string) (io.ReadCloser, container.PathStat, error) { assert.Check(t, is.Equal("container", ctr)) - readCloser, err := archive.Tar(destDir.Path(), archive.Uncompressed) + readCloser, err := archive.Tar(srcDir.Path(), archive.Uncompressed) return readCloser, container.PathStat{}, err }, })