From d19cfb6f6f60f4ca5ea952cd794c5ac9d439dbaf Mon Sep 17 00:00:00 2001 From: Timofey Kirillov Date: Mon, 21 Mar 2022 11:42:18 +0300 Subject: [PATCH] fix: context extraction error Context extraction error may occur when an archive contains file node without parent directory node. Fixes https://github.com/werf/werf/issues/4260. Signed-off-by: Timofey Kirillov --- pkg/util/archive.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/util/archive.go b/pkg/util/archive.go index c388afe798..f78e8a42b9 100644 --- a/pkg/util/archive.go +++ b/pkg/util/archive.go @@ -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)