Skip to content

Rewrite of download #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move initialization of tools in package tools
  • Loading branch information
matteosuppo committed May 4, 2016
commit 4f8115c0df588741d0ccbb5ab03fd876d7ddae74
4 changes: 3 additions & 1 deletion hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"fmt"

log "github.com/Sirupsen/logrus"
"github.com/arduino/arduino-create-agent/tools"
"github.com/kardianos/osext"
//"os"
"os/exec"
Expand Down Expand Up @@ -191,7 +193,7 @@ func checkCmd(m []byte) {
} else if strings.HasPrefix(sl, "downloadtool") {
args := strings.Split(s, " ")
if len(args) > 2 {
go spDownloadTool(args[1], args[2])
go tools.Download(args[1], args[2])
}
} else if strings.HasPrefix(sl, "bufferalgorithm") {
go spBufferAlgorithms()
Expand Down
15 changes: 6 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ package main
import (
"flag"
"os"
"os/user"
"path/filepath"
"runtime/debug"
"strconv"
"text/template"
"time"

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

var logger_ws logWriter

func createToolsDir() string {
usr, _ := user.Current()
return usr.HomeDir + "/.arduino-create"
}

func homeHandler(c *gin.Context) {
homeTemplate.Execute(c.Writer, c.Request.Host)
}
Expand Down Expand Up @@ -92,8 +90,7 @@ func main() {
src, _ := osext.Executable()
dest := filepath.Dir(src)

os.Mkdir(tempToolsPath, 0777)
hideFile(tempToolsPath)
tools.CreateDir()

if embedded_autoextract {
// save the config.ini (if it exists)
Expand Down
3 changes: 0 additions & 3 deletions seriallist_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,5 @@ func associateVidPidWithPort(ports []OsSerialPort) []OsSerialPort {
return ports
}

func hideFile(path string) {
}

func tellCommandNotToSpawnShell(_ *exec.Cmd) {
}
3 changes: 0 additions & 3 deletions seriallist_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,5 @@ func associateVidPidWithPort(ports []OsSerialPort) []OsSerialPort {
return ports
}

func hideFile(path string) {
}

func tellCommandNotToSpawnShell(_ *exec.Cmd) {
}
14 changes: 4 additions & 10 deletions seriallist_windows.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package main

import (
log "github.com/Sirupsen/logrus"
"github.com/mattn/go-ole"
"github.com/mattn/go-ole/oleutil"
"os"
"os/exec"
"regexp"
"strings"
"sync"
"syscall"

log "github.com/Sirupsen/logrus"
"github.com/mattn/go-ole"
"github.com/mattn/go-ole/oleutil"
)

var (
Expand Down Expand Up @@ -62,13 +63,6 @@ func getListSynchronously() {

}

func hideFile(path string) {
cpath, cpathErr := syscall.UTF16PtrFromString(path)
if cpathErr != nil {
}
syscall.SetFileAttributes(cpath, syscall.FILE_ATTRIBUTE_HIDDEN)
}

func getListViaWmiPnpEntity() ([]OsSerialPort, os.SyscallError) {

//log.Println("Doing getListViaWmiPnpEntity()")
Expand Down
5 changes: 5 additions & 0 deletions tools/hidefile_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package tools

func hideFile(path string) {

}
5 changes: 5 additions & 0 deletions tools/hidefile_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package tools

func hideFile(path string) {

}
10 changes: 10 additions & 0 deletions tools/hidefile_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tools

import "syscall"

func hideFile(path string) {
cpath, cpathErr := syscall.UTF16PtrFromString(path)
if cpathErr != nil {
}
syscall.SetFileAttributes(cpath, syscall.FILE_ATTRIBUTE_HIDDEN)
}
24 changes: 24 additions & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package tools

import (
"os"
"os/user"
)

func dir() string {
usr, _ := user.Current()
return usr.HomeDir + "/.arduino-create"
}

// CreateDir creates the directory where the tools will be stored
func CreateDir() {
directory := dir()
os.Mkdir(directory, 0777)
hideFile(directory)
}

// Download will parse the index at the indexURL for the tool to download
func Download(name, indexURL string) {
if _, err := os.Stat(dir() + "/" + name); err != nil {
}
}