Skip to content

Commit 05d5d16

Browse files
committed
Notify with success and errors when downloading a tool
1 parent e4be41e commit 05d5d16

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

download.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package main
33

44
import (
5+
"encoding/json"
56
"errors"
67
log "github.com/Sirupsen/logrus"
78
"io"
@@ -92,13 +93,30 @@ func spDownloadTool(name string, url string) {
9293
fileName, err := downloadFromUrl(url + "/" + name + "-" + runtime.GOOS + "-" + runtime.GOARCH + ".zip")
9394
if err != nil {
9495
log.Error("Could not download flashing tools!")
96+
mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()}
97+
mapB, _ := json.Marshal(mapD)
98+
h.broadcastSys <- mapB
99+
return
100+
}
101+
err = Unzip(fileName, tempToolsPath)
102+
if err != nil {
103+
log.Error("Could not unzip flashing tools!")
104+
mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()}
105+
mapB, _ := json.Marshal(mapD)
106+
h.broadcastSys <- mapB
95107
return
96108
}
97-
Unzip(fileName, tempToolsPath)
98109
} else {
99110
log.Info("Tool already present, skipping download")
100111
}
101112

102113
// will be something like ${tempfolder}/avrdude/bin/avrdude
103114
globalToolsMap["{runtime.tools."+name+".path}"] = tempToolsPath + "/" + name
115+
116+
log.Info("Map Updated")
117+
mapD := map[string]string{"DownloadStatus": "Success", "Msg": "Map Updated"}
118+
mapB, _ := json.Marshal(mapD)
119+
h.broadcastSys <- mapB
120+
return
121+
104122
}

0 commit comments

Comments
 (0)