Skip to content

Commit cc10dc9

Browse files
committed
Find the tool given the packager
1 parent 9874642 commit cc10dc9

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

hub.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ func checkCmd(m []byte) {
192192
} else if strings.HasPrefix(sl, "downloadtool") {
193193
go func() {
194194
args := strings.Split(s, " ")
195-
var tool, toolVersion, behaviour string
195+
var tool, toolVersion, pack, behaviour string
196196
toolVersion = "latest"
197+
pack = "arduino"
197198
behaviour = "keep"
198199
if len(args) <= 1 {
199200
mapD := map[string]string{"DownloadStatus": "Error", "Msg": "Not enough arguments"}
@@ -208,10 +209,13 @@ func checkCmd(m []byte) {
208209
toolVersion = args[2]
209210
}
210211
if len(args) > 3 {
211-
behaviour = args[3]
212+
pack = args[3]
213+
}
214+
if len(args) > 4 {
215+
behaviour = args[4]
212216
}
213217

214-
err := Tools.Download(tool, toolVersion, behaviour)
218+
err := Tools.Download(pack, tool, toolVersion, behaviour)
215219
if err != nil {
216220
mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()}
217221
mapB, _ := json.Marshal(mapD)

tools/download.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (t *Tools) DownloadPackageIndex(index_file, signature_file string) error {
130130
// It will extract it in a folder in .arduino-create, and it will update the
131131
// Installed map.
132132
//
133+
// pack contains the packager of the tool
133134
// name contains the name of the tool.
134135
// version contains the version of the tool.
135136
// behaviour contains the strategy to use when there is already a tool installed
@@ -140,7 +141,7 @@ func (t *Tools) DownloadPackageIndex(index_file, signature_file string) error {
140141
// If version is not "latest" and behaviour is "replace", it will download the
141142
// version again. If instead behaviour is "keep" it will not download the version
142143
// if it already exists.
143-
func (t *Tools) Download(name, version, behaviour string) error {
144+
func (t *Tools) Download(pack, name, version, behaviour string) error {
144145

145146
index_file := path.Join(t.Directory, "package_index.json")
146147
signature_file := path.Join(t.Directory, "package_index.json.sig")
@@ -169,10 +170,10 @@ func (t *Tools) Download(name, version, behaviour string) error {
169170
t.Logger.Println(string(body))
170171

171172
// Find the tool by name
172-
correctTool, correctSystem := findTool(name, version, data)
173+
correctTool, correctSystem := findTool(pack, name, version, data)
173174

174175
if correctTool.Name == "" || correctSystem.URL == "" {
175-
t.Logger.Println("We couldn't find a tool with the name " + name + " and version " + version)
176+
t.Logger.Println("We couldn't find a tool with the name " + name + " and version " + version + " packaged by " + pack)
176177
return nil
177178
}
178179

@@ -255,11 +256,14 @@ func (t *Tools) Download(name, version, behaviour string) error {
255256
return t.writeMap()
256257
}
257258

258-
func findTool(name, version string, data index) (tool, system) {
259+
func findTool(pack, name, version string, data index) (tool, system) {
259260
var correctTool tool
260261
correctTool.Version = "0.0"
261262

262263
for _, p := range data.Packages {
264+
if p.Name != pack {
265+
continue
266+
}
263267
for _, t := range p.Tools {
264268
if version != "latest" {
265269
if t.Name == name && t.Version == version {

0 commit comments

Comments
 (0)