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

Handle the case where files appear in the tar before their directories. #98

Merged
merged 1 commit into from
Sep 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions pkg/util/tar_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,25 @@ func unpackTar(tr *tar.Reader, path string) error {

// if its a dir and it doesn't exist create it
case tar.TypeDir:
if _, err := os.Stat(target); err != nil {
if _, err := os.Stat(target); os.IsNotExist(err) {
if err := os.MkdirAll(target, mode); err != nil {
glog.Errorf("Error creating directory %s while untarring", target)
return err
}
continue
} else {
if err := os.Chmod(target, mode); err != nil {
return err
}
}

// if it's a file create it
case tar.TypeReg:

// It's possible for a file to be included before the directory it's in is created.
baseDir := filepath.Dir(target)
if _, err := os.Stat(baseDir); os.IsNotExist(err) {
if err := os.MkdirAll(baseDir, 0755); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use the inherited mode from the header? header.FileInfo().mode() above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the file mode doesn't work for the directory mode. I'm not really sure what the right thing to do here is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah I see, I'm not really sure either. Maybe we create the directory with these permissions and then create the files inside of it with the header's permissions? I'm just worried that file permissions will be different than what's expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah how's this?

return err
}
}
currFile, err := os.OpenFile(target, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, mode)
if err != nil {
glog.Errorf("Error opening file %s", target)
Expand Down