Skip to content

Commit

Permalink
fix: untar empty directories (#11240)
Browse files Browse the repository at this point in the history
  • Loading branch information
lheinlen authored Jun 20, 2023
1 parent abc4e8f commit 245af38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions workflow/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,10 @@ func untar(tarPath string, destPath string) error {
if err != nil {
return err
}
case tar.TypeDir:
if err := os.MkdirAll(target, 0o755); 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
6 changes: 6 additions & 0 deletions workflow/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func TestUntar(t *testing.T) {
destPath := "testdata/untarredDir"
filePath := "testdata/untarredDir/file"
linkPath := "testdata/untarredDir/link"
emptyDirPath := "testdata/untarredDir/empty-dir"

// test
err := untar(tarPath, destPath)
Expand All @@ -294,12 +295,17 @@ func TestUntar(t *testing.T) {
fileInfo, err = os.Stat(linkPath)
assert.NoError(t, err)
assert.True(t, fileInfo.Mode().IsRegular())
fileInfo, err = os.Stat(emptyDirPath)
assert.NoError(t, err)
assert.True(t, fileInfo.Mode().IsDir())

// cleanup
err = os.Remove(linkPath)
assert.NoError(t, err)
err = os.Remove(filePath)
assert.NoError(t, err)
err = os.Remove(emptyDirPath)
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.

0 comments on commit 245af38

Please sign in to comment.