Skip to content

Commit b6c0cbc

Browse files
matteosuppofacchinm
authored andcommitted
Move initialization of tools in package tools
1 parent 54b274f commit b6c0cbc

9 files changed

+57
-26
lines changed

hub.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package main
22

33
import (
44
"fmt"
5+
56
log "github.com/Sirupsen/logrus"
7+
"github.com/arduino/arduino-create-agent/tools"
68
"github.com/kardianos/osext"
79
//"os"
810
"os/exec"
@@ -191,7 +193,7 @@ func checkCmd(m []byte) {
191193
} else if strings.HasPrefix(sl, "downloadtool") {
192194
args := strings.Split(s, " ")
193195
if len(args) > 2 {
194-
go spDownloadTool(args[1], args[2])
196+
go tools.Download(args[1], args[2])
195197
}
196198
} else if strings.HasPrefix(sl, "bufferalgorithm") {
197199
go spBufferAlgorithms()

main.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ package main
66
import (
77
"flag"
88
"os"
9-
"os/user"
109
"path/filepath"
1110
"runtime/debug"
1211
"strconv"
1312
"text/template"
1413
"time"
1514

1615
log "github.com/Sirupsen/logrus"
16+
<<<<<<< e73846650fde9b0955aa35e237100ec552af47fb
17+
=======
18+
"github.com/arduino/arduino-create-agent/tools"
19+
"github.com/carlescere/scheduler"
20+
>>>>>>> Move initialization of tools in package tools
1721
"github.com/gin-gonic/gin"
1822
"github.com/itsjamie/gin-cors"
1923
"github.com/kardianos/osext"
@@ -39,7 +43,6 @@ var (
3943
appName = flag.String("appName", "", "")
4044
genCert = flag.Bool("generateCert", false, "")
4145
globalToolsMap = make(map[string]string)
42-
tempToolsPath = createToolsDir()
4346
port string
4447
portSSL string
4548
origins = flag.String("origins", "", "Allowed origin list for CORS")
@@ -60,11 +63,6 @@ func (u *logWriter) Write(p []byte) (n int, err error) {
6063

6164
var logger_ws logWriter
6265

63-
func createToolsDir() string {
64-
usr, _ := user.Current()
65-
return usr.HomeDir + "/.arduino-create"
66-
}
67-
6866
func homeHandler(c *gin.Context) {
6967
homeTemplate.Execute(c.Writer, c.Request.Host)
7068
}
@@ -92,8 +90,7 @@ func main() {
9290
src, _ := osext.Executable()
9391
dest := filepath.Dir(src)
9492

95-
os.Mkdir(tempToolsPath, 0777)
96-
hideFile(tempToolsPath)
93+
tools.CreateDir()
9794

9895
if embedded_autoextract {
9996
// save the config.ini (if it exists)

seriallist_darwin.go

-3
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,5 @@ func associateVidPidWithPort(ports []OsSerialPort) []OsSerialPort {
6363
return ports
6464
}
6565

66-
func hideFile(path string) {
67-
}
68-
6966
func tellCommandNotToSpawnShell(_ *exec.Cmd) {
7067
}

seriallist_linux.go

-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,5 @@ func associateVidPidWithPort(ports []OsSerialPort) []OsSerialPort {
3535
return ports
3636
}
3737

38-
func hideFile(path string) {
39-
}
40-
4138
func tellCommandNotToSpawnShell(_ *exec.Cmd) {
4239
}

seriallist_windows.go

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package main
22

33
import (
4-
log "github.com/Sirupsen/logrus"
5-
"github.com/mattn/go-ole"
6-
"github.com/mattn/go-ole/oleutil"
74
"os"
85
"os/exec"
96
"regexp"
107
"strings"
118
"sync"
129
"syscall"
10+
11+
log "github.com/Sirupsen/logrus"
12+
"github.com/mattn/go-ole"
13+
"github.com/mattn/go-ole/oleutil"
1314
)
1415

1516
var (
@@ -62,13 +63,6 @@ func getListSynchronously() {
6263

6364
}
6465

65-
func hideFile(path string) {
66-
cpath, cpathErr := syscall.UTF16PtrFromString(path)
67-
if cpathErr != nil {
68-
}
69-
syscall.SetFileAttributes(cpath, syscall.FILE_ATTRIBUTE_HIDDEN)
70-
}
71-
7266
func getListViaWmiPnpEntity() ([]OsSerialPort, os.SyscallError) {
7367

7468
//log.Println("Doing getListViaWmiPnpEntity()")

tools/hidefile_darwin.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package tools
2+
3+
func hideFile(path string) {
4+
5+
}

tools/hidefile_linux.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package tools
2+
3+
func hideFile(path string) {
4+
5+
}

tools/hidefile_windows.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package tools
2+
3+
import "syscall"
4+
5+
func hideFile(path string) {
6+
cpath, cpathErr := syscall.UTF16PtrFromString(path)
7+
if cpathErr != nil {
8+
}
9+
syscall.SetFileAttributes(cpath, syscall.FILE_ATTRIBUTE_HIDDEN)
10+
}

tools/tools.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package tools
2+
3+
import (
4+
"os"
5+
"os/user"
6+
)
7+
8+
func dir() string {
9+
usr, _ := user.Current()
10+
return usr.HomeDir + "/.arduino-create"
11+
}
12+
13+
// CreateDir creates the directory where the tools will be stored
14+
func CreateDir() {
15+
directory := dir()
16+
os.Mkdir(directory, 0777)
17+
hideFile(directory)
18+
}
19+
20+
// Download will parse the index at the indexURL for the tool to download
21+
func Download(name, indexURL string) {
22+
if _, err := os.Stat(dir() + "/" + name); err != nil {
23+
}
24+
}

0 commit comments

Comments
 (0)