From 6c7a6993ac3adabc5da6c2382623b256911a16ec Mon Sep 17 00:00:00 2001 From: Steven White Date: Wed, 2 Nov 2022 15:35:55 -0400 Subject: [PATCH 1/2] fix: support symlinks in artifact untar Signed-off-by: Steven White --- workflow/executor/executor.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/workflow/executor/executor.go b/workflow/executor/executor.go index 1eff992a7292..36967f5d5375 100644 --- a/workflow/executor/executor.go +++ b/workflow/executor/executor.go @@ -892,6 +892,11 @@ func untar(tarPath string, destPath string) error { return err } switch header.Typeflag { + case tar.TypeSymlink: + err := os.Symlink(header.Linkname, target) + if err != nil { + return err + } case tar.TypeReg: f, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode)) if err != nil { From 0d8a381a40b4a3edc5ada5244c8c6732640e73d5 Mon Sep 17 00:00:00 2001 From: Steven White Date: Wed, 2 Nov 2022 15:36:03 -0400 Subject: [PATCH 2/2] test: add test case for symlinks; update testdata Signed-off-by: Steven White --- workflow/executor/executor_test.go | 16 ++++++++++++++-- workflow/executor/testdata/file.tar.gz | Bin 124 -> 144 bytes workflow/executor/testdata/link | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) create mode 120000 workflow/executor/testdata/link diff --git a/workflow/executor/executor_test.go b/workflow/executor/executor_test.go index 5eeb216f2368..53964281239d 100644 --- a/workflow/executor/executor_test.go +++ b/workflow/executor/executor_test.go @@ -277,18 +277,30 @@ func TestUnzip(t *testing.T) { func TestUntar(t *testing.T) { tarPath := "testdata/file.tar.gz" - destPath := "testdata/untarredFile" + destPath := "testdata/untarredDir" + filePath := "testdata/untarredDir/file" + linkPath := "testdata/untarredDir/link" // test err := untar(tarPath, destPath) assert.NoError(t, err) - // check untarred file + // check untarred contents fileInfo, err := os.Stat(destPath) assert.NoError(t, err) + assert.True(t, fileInfo.Mode().IsDir()) + fileInfo, err = os.Stat(filePath) + assert.NoError(t, err) + assert.True(t, fileInfo.Mode().IsRegular()) + fileInfo, err = os.Stat(linkPath) + assert.NoError(t, err) assert.True(t, fileInfo.Mode().IsRegular()) // cleanup + err = os.Remove(linkPath) + assert.NoError(t, err) + err = os.Remove(filePath) + assert.NoError(t, err) err = os.Remove(destPath) assert.NoError(t, err) } diff --git a/workflow/executor/testdata/file.tar.gz b/workflow/executor/testdata/file.tar.gz index 1cefc6b53e0ac0935e639482ca392ee509c7a4f9..1e9a92907913872caa9bd862a4be1340cf758d2e 100644 GIT binary patch literal 144 zcmV;B0B`>viwFRmvtnZa153-yNoAlhFfcGMGci#B(dK4mVA{Y4!iNC`Lla|T15;x| zV{;<~14CmIBLfBn16n%_1WJob5{rONDK1GZOU*0K$SlDg9zbPjX?V diff --git a/workflow/executor/testdata/link b/workflow/executor/testdata/link new file mode 120000 index 000000000000..1a010b1c0f08 --- /dev/null +++ b/workflow/executor/testdata/link @@ -0,0 +1 @@ +file \ No newline at end of file