Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Preserve symlinks in untar. Fixes #9948 #9949

Merged
merged 2 commits into from Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions workflow/executor/executor.go
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
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