Skip to content

Commit ecf67f8

Browse files
committed
Foxed conflicts in main
1 parent 4734405 commit ecf67f8

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

main.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
log "github.com/Sirupsen/logrus"
1717
"github.com/arduino/arduino-create-agent/tools"
18+
"github.com/arduino/arduino-create-agent/utilities"
1819
"github.com/gin-gonic/gin"
1920
"github.com/itsjamie/gin-cors"
2021
"github.com/kardianos/osext"

utilities/utilities.go

+39
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package utilities
22

33
import (
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+
}

0 commit comments

Comments
 (0)