-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrungo_windows.go
77 lines (66 loc) · 1.94 KB
/
rungo_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"archive/zip"
"io"
"os"
"os/exec"
"path/filepath"
log "github.com/Sirupsen/logrus"
"github.com/pkg/errors"
)
func runGo(binary, baseDir string, args []string) error {
goBinary := filepath.Join(baseDir, "go", "bin", binary)
cmd := exec.Command(goBinary, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
log.Debugf("Executing %q with arguments %v", goBinary, args)
return cmd.Run()
}
func extractFile(golangArchive, baseDir string) error {
log.Infof("Extracting %q", golangArchive)
err := os.MkdirAll(baseDir, os.ModeDir|0755)
if err != nil {
return errors.Wrapf(err, "mkdir %q failed", baseDir)
}
zipReader, err := zip.OpenReader(golangArchive)
if err != nil {
return errors.Wrapf(err, "open reader for file %q failed", golangArchive)
}
defer zipReader.Close()
fileCount := 0
for _, fileInZip := range zipReader.File {
fileContents, err := fileInZip.Open()
if err != nil {
return errors.Wrapf(err, "zip open of %q failed", fileInZip.Name)
}
path := filepath.Join(baseDir, fileInZip.Name)
fileInfo := fileInZip.FileHeader.FileInfo()
if fileInfo.IsDir() {
err = os.MkdirAll(path, fileInfo.Mode())
if err != nil {
return errors.Wrapf(err, "mkdir %q failed", path)
}
continue
} else {
// Make directory containing the current file, if needed. Some tarballs don't include the top-level directory entry
err = os.MkdirAll(filepath.Dir(path), os.ModeDir|0755)
if err != nil {
return errors.Wrapf(err, "mkdir %q failed", path)
}
}
fileOnDisk, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, fileInfo.Mode())
if err != nil {
return errors.Wrapf(err, "open file %q failed", path)
}
_, err = io.Copy(fileOnDisk, fileContents)
if err != nil {
fileOnDisk.Close()
return errors.Wrapf(err, "copy for %q failed", path)
}
fileOnDisk.Close()
fileCount++
}
log.Debugf("Wrote %d files to %q", fileCount, baseDir)
return nil
}