Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit a2b2536

Browse files
committed
Handle the case where files appear in the tar before their directories.
1 parent 46ffad9 commit a2b2536

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pkg/util/tar_utils.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,23 @@ func unpackTar(tr *tar.Reader, path string) error {
5858

5959
// if its a dir and it doesn't exist create it
6060
case tar.TypeDir:
61-
if _, err := os.Stat(target); err != nil {
61+
if _, err := os.Stat(target); os.IsNotExist(err) {
6262
if err := os.MkdirAll(target, mode); err != nil {
63-
glog.Errorf("Error creating directory %s while untarring", target)
6463
return err
6564
}
6665
continue
6766
}
6867

6968
// if it's a file create it
7069
case tar.TypeReg:
71-
70+
// It's possible for a file to be included before the directory it's in is created.
71+
baseDir := filepath.Dir(target)
72+
if _, err := os.Stat(baseDir); os.IsNotExist(err) {
73+
if err := os.MkdirAll(baseDir, 0755); err != nil {
74+
return err
75+
}
76+
continue
77+
}
7278
currFile, err := os.OpenFile(target, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, mode)
7379
if err != nil {
7480
glog.Errorf("Error opening file %s", target)

0 commit comments

Comments
 (0)