Skip to content

add checktool endpoint and force download #37

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
50 changes: 30 additions & 20 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,38 @@ func downloadFromUrl(url string) (filename string, err error) {
return fileName, nil
}

func spDownloadTool(name string, url string) {
func spCheckToolVersion(name string) {
var outlist []string
dirlist, err := ioutil.ReadDir(tempToolsPath + "/")
if err == nil {
for _, element := range dirlist {
if element.IsDir() && strings.Contains(element.Name(), name) {
outlist = append(outlist, element.Name())
}
}
}
mapD := map[string][]string{"ToolVersions": outlist}
mapB, _ := json.Marshal(mapD)
h.broadcastSys <- mapB
}

if _, err := os.Stat(tempToolsPath + "/" + name); err != nil {
func spDownloadTool(name string, url string) {

fileName, err := downloadFromUrl(url + "/" + name + "-" + runtime.GOOS + "-" + runtime.GOARCH + ".zip")
if err != nil {
log.Error("Could not download flashing tools!")
mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()}
mapB, _ := json.Marshal(mapD)
h.broadcastSys <- mapB
return
}
err = UnzipWrapper(fileName, tempToolsPath)
if err != nil {
log.Error("Could not unzip flashing tools!")
mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()}
mapB, _ := json.Marshal(mapD)
h.broadcastSys <- mapB
return
}
} else {
log.Info("Tool already present, skipping download")
fileName, err := downloadFromUrl(url + "/" + name + "-" + runtime.GOOS + "-" + runtime.GOARCH + ".zip")
if err != nil {
log.Error("Could not download flashing tools!")
mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()}
mapB, _ := json.Marshal(mapD)
h.broadcastSys <- mapB
return
}
err = UnzipWrapper(fileName, tempToolsPath)
if err != nil {
log.Error("Could not unzip flashing tools!")
mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()}
mapB, _ := json.Marshal(mapD)
h.broadcastSys <- mapB
return
}

folders, _ := ioutil.ReadDir(tempToolsPath)
Expand Down
5 changes: 5 additions & 0 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ func checkCmd(m []byte) {
if len(args) > 2 {
go spDownloadTool(args[1], args[2])
}
} else if strings.HasPrefix(sl, "checktool") {
args := strings.Split(s, " ")
if len(args) > 1 {
go spCheckToolVersion(args[1])
}
} else if strings.HasPrefix(sl, "bufferalgorithm") {
go spBufferAlgorithms()
} else if strings.HasPrefix(sl, "log") {
Expand Down