Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c51d119

Browse files
committedMar 1, 2016
Move initialization of tools in package tools
1 parent 3b7c7a9 commit c51d119

File tree

9 files changed

+53
-26
lines changed

9 files changed

+53
-26
lines changed
 

‎hub.go

Lines changed: 3 additions & 1 deletion
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"
@@ -187,7 +189,7 @@ func checkCmd(m []byte) {
187189
} else if strings.HasPrefix(sl, "downloadtool") {
188190
args := strings.Split(s, " ")
189191
if len(args) > 2 {
190-
go spDownloadTool(args[1], args[2])
192+
go tools.Download(args[1], args[2])
191193
}
192194
} else if strings.HasPrefix(sl, "bufferalgorithm") {
193195
go spBufferAlgorithms()

‎main.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ 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+
"github.com/arduino/arduino-create-agent/tools"
1717
"github.com/carlescere/scheduler"
1818
"github.com/gin-gonic/gin"
1919
"github.com/itsjamie/gin-cors"
@@ -41,7 +41,6 @@ var (
4141
appName = flag.String("appName", "", "")
4242
genCert = flag.Bool("generateCert", false, "")
4343
globalToolsMap = make(map[string]string)
44-
tempToolsPath = createToolsDir()
4544
port string
4645
portSSL string
4746
origins = flag.String("origins", "", "Allowed origin list for CORS")
@@ -61,11 +60,6 @@ func (u *logWriter) Write(p []byte) (n int, err error) {
6160

6261
var logger_ws logWriter
6362

64-
func createToolsDir() string {
65-
usr, _ := user.Current()
66-
return usr.HomeDir + "/.arduino-create"
67-
}
68-
6963
func homeHandler(c *gin.Context) {
7064
homeTemplate.Execute(c.Writer, c.Request.Host)
7165
}
@@ -93,8 +87,7 @@ func main() {
9387
src, _ := osext.Executable()
9488
dest := filepath.Dir(src)
9589

96-
os.Mkdir(tempToolsPath, 0777)
97-
hideFile(tempToolsPath)
90+
tools.CreateDir()
9891

9992
if embedded_autoextract {
10093
// save the config.ini (if it exists)

‎seriallist_darwin.go

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 4 additions & 10 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 24 additions & 0 deletions
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)
Please sign in to comment.