Skip to content

Commit

Permalink
fix: context extraction error
Browse files Browse the repository at this point in the history
Context extraction error may occur when an archive contains file node without parent directory node.

Fixes #4260.

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Mar 21, 2022
1 parent 69e1bb0 commit d19cfb6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/util/archive.go
Expand Up @@ -192,6 +192,10 @@ func ExtractTar(tarFileReader io.Reader, dstDir string) error {
return fmt.Errorf("unable to create new dir %q while extracting tar: %s", tarEntryPath, err)
}
case tar.TypeReg, tar.TypeSymlink, tar.TypeLink, tar.TypeGNULongName, tar.TypeGNULongLink:
if err := os.MkdirAll(filepath.Dir(tarEntryPath), os.ModePerm); err != nil {
return fmt.Errorf("unable to create new directory %q while extracting tar: %w", filepath.Dir(tarEntryPath), err)
}

file, err := os.OpenFile(tarEntryPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, tarEntryFileInfo.Mode())
if err != nil {
return fmt.Errorf("unable to create new file %q while extracting tar: %s", tarEntryPath, err)
Expand Down

0 comments on commit d19cfb6

Please sign in to comment.