Skip to content

Commit

Permalink
More logging for unpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
gertjaap committed Jul 2, 2019
1 parent a2854dc commit 2da84b2
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,19 @@ func UnpackZip(archive, unpackPath string) error {

for _, f := range r.File {
targetPath := filepath.Join(unpackPath, f.Name)
os.MkdirAll(filepath.Dir(targetPath), 0700)
logging.Debugf("[Zip] Unpacking [%s] to [%s]\n", f.Name, targetPath)
err := os.MkdirAll(filepath.Dir(targetPath), 0755)
if err != nil {
logging.Warnf("[Zip] Failure to create directory [%s]: %s", filepath.Dir(targetPath), err.Error())
} else {
logging.Debugf("[Zip] Created directory [%s]\n", filepath.Dir(targetPath))
}
outFile, err := os.OpenFile(targetPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil {
return err
}
defer outFile.Close()

logging.Debugf("[Zip] Extracting [%s]\n", targetPath)
rc, err := f.Open()
if err != nil {
return err
Expand Down Expand Up @@ -171,13 +177,19 @@ func UnpackTar(archive, unpackPath string) error {
continue
case tar.TypeReg:
targetPath := filepath.Join(unpackPath, name)
os.MkdirAll(filepath.Dir(targetPath), 0700)
outFile, err := os.OpenFile(targetPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0700)
logging.Debugf("[Tar] Unpacking [%s] to [%s]\n", name, targetPath)
err := os.MkdirAll(filepath.Dir(targetPath), 0755)
if err != nil {
logging.Warnf("[Tar] Failure to create directory [%s]: %s", filepath.Dir(targetPath), err.Error())
} else {
logging.Debugf("[Tar] Created directory [%s]\n", filepath.Dir(targetPath))
}
outFile, err := os.OpenFile(targetPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
return err
}
defer outFile.Close()

logging.Debugf("[Tar] Extracting [%s]\n", targetPath)
_, err = io.Copy(outFile, tarReader)
if err != nil {
return err
Expand Down

0 comments on commit 2da84b2

Please sign in to comment.