From 74e4bd89df5022ffa0fb5b5afa5d9d9d1c462efd Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 16 Mar 2017 18:48:37 +0100 Subject: [PATCH] Fix permission problems while unzipping --- src/arduino.cc/builder/sketch_loader.go | 2 +- src/arduino.cc/builder/utils/utils.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/arduino.cc/builder/sketch_loader.go b/src/arduino.cc/builder/sketch_loader.go index 2dddfce4..48625543 100644 --- a/src/arduino.cc/builder/sketch_loader.go +++ b/src/arduino.cc/builder/sketch_loader.go @@ -69,7 +69,7 @@ func (s *SketchLoader) Run(ctx *types.Context) error { dir, _ := ioutil.TempDir("", "arduino_sketch_zip_temp") sketchLocation, err = utils.ExtractZip(sketchLocation, dir) if err != nil { - return nil + panic(err) } mainSketchFileName := filepath.Base(sketchLocation) + ".ino" sketchLocation = filepath.Join(sketchLocation, mainSketchFileName) diff --git a/src/arduino.cc/builder/utils/utils.go b/src/arduino.cc/builder/utils/utils.go index 445024d4..c96b75f3 100644 --- a/src/arduino.cc/builder/utils/utils.go +++ b/src/arduino.cc/builder/utils/utils.go @@ -486,9 +486,12 @@ func ExtractZip(filePath string, location string) (string, error) { for _, f := range r.File { fullname := filepath.Join(location, strings.Replace(f.Name, "", "", -1)) if f.FileInfo().IsDir() { - os.MkdirAll(fullname, f.FileInfo().Mode().Perm()) + os.MkdirAll(fullname, 0755) } else { - os.MkdirAll(filepath.Dir(fullname), 0755) + _, err := os.Stat(filepath.Dir(fullname)) + if err != nil { + os.MkdirAll(filepath.Dir(fullname), 0755) + } perms := f.FileInfo().Mode().Perm() out, err := os.OpenFile(fullname, os.O_CREATE|os.O_RDWR, perms) if err != nil {