Skip to content

Commit

Permalink
fix: Preserve symlinks in untar. Fixes argoproj#9948 (argoproj#9949)
Browse files Browse the repository at this point in the history
Signed-off-by: Steven White <[email protected]>
  • Loading branch information
swhite24 authored Nov 2, 2022
1 parent a5b31b3 commit 4f1451e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions workflow/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 14 additions & 2 deletions workflow/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Binary file modified workflow/executor/testdata/file.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions workflow/executor/testdata/link

0 comments on commit 4f1451e

Please sign in to comment.