File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import (
15
15
16
16
log "github.com/Sirupsen/logrus"
17
17
"github.com/arduino/arduino-create-agent/tools"
18
+ "github.com/arduino/arduino-create-agent/utilities"
18
19
"github.com/gin-gonic/gin"
19
20
"github.com/itsjamie/gin-cors"
20
21
"github.com/kardianos/osext"
Original file line number Diff line number Diff line change 1
1
package utilities
2
2
3
3
import (
4
+ "archive/zip"
4
5
"bytes"
5
6
"errors"
6
7
"io"
7
8
"io/ioutil"
8
9
"os"
9
10
"os/exec"
11
+ "path"
10
12
"path/filepath"
11
13
)
12
14
@@ -87,3 +89,40 @@ func call(stack []*exec.Cmd, pipes []*io.PipeWriter) (err error) {
87
89
}
88
90
return stack [0 ].Wait ()
89
91
}
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