File tree Expand file tree Collapse file tree 2 files changed +41
-5
lines changed
Expand file tree Collapse file tree 2 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -14,11 +14,8 @@ import (
1414 "time"
1515
1616 log "github.com/Sirupsen/logrus"
17- << << << < e73846650fde9b0955aa35e237100ec552af47fb
18- == == == =
1917 "github.com/arduino/arduino-create-agent/tools"
20- "github.com/carlescere/scheduler"
21- >> >> >> > Move initialization of tools in package tools
18+ "github.com/arduino/arduino-create-agent/utilities"
2219 "github.com/gin-gonic/gin"
2320 "github.com/itsjamie/gin-cors"
2421 "github.com/kardianos/osext"
@@ -105,7 +102,7 @@ func main() {
105102 // save the config.ini (if it exists)
106103 if _ , err := os .Stat (dest + "/" + * configIni ); os .IsNotExist (err ) {
107104 log .Println ("First run, unzipping self" )
108- err := Unzip (src , dest )
105+ err := utilities . Unzip (src , dest )
109106 log .Println ("Self extraction, err:" , err )
110107 }
111108
Original file line number Diff line number Diff line change 11package utilities
22
33import (
4+ "archive/zip"
45 "bytes"
56 "errors"
67 "io"
78 "io/ioutil"
89 "os"
910 "os/exec"
11+ "path"
1012 "path/filepath"
1113)
1214
@@ -87,3 +89,40 @@ func call(stack []*exec.Cmd, pipes []*io.PipeWriter) (err error) {
8789 }
8890 return stack [0 ].Wait ()
8991}
92+
93+ func Unzip (zippath string , destination string ) (err error ) {
94+ r , err := zip .OpenReader (zippath )
95+ if err != nil {
96+ return err
97+ }
98+ for _ , f := range r .File {
99+ fullname := path .Join (destination , f .Name )
100+ if f .FileInfo ().IsDir () {
101+ os .MkdirAll (fullname , f .FileInfo ().Mode ().Perm ())
102+ } else {
103+ os .MkdirAll (filepath .Dir (fullname ), 0755 )
104+ perms := f .FileInfo ().Mode ().Perm ()
105+ out , err := os .OpenFile (fullname , os .O_CREATE | os .O_RDWR , perms )
106+ if err != nil {
107+ return err
108+ }
109+ rc , err := f .Open ()
110+ if err != nil {
111+ return err
112+ }
113+ _ , err = io .CopyN (out , rc , f .FileInfo ().Size ())
114+ if err != nil {
115+ return err
116+ }
117+ rc .Close ()
118+ out .Close ()
119+
120+ mtime := f .FileInfo ().ModTime ()
121+ err = os .Chtimes (fullname , mtime , mtime )
122+ if err != nil {
123+ return err
124+ }
125+ }
126+ }
127+ return
128+ }
You can’t perform that action at this time.
0 commit comments