Skip to content

Commit 244ca6b

Browse files
authored
Merge pull request #125 from arduino/download_versions
Find the tool given the packager
2 parents 9874642 + 00f636d commit 244ca6b

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

hub.go

+12-4
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"}
@@ -205,13 +206,20 @@ func checkCmd(m []byte) {
205206
tool = args[1]
206207
}
207208
if len(args) > 2 {
208-
toolVersion = args[2]
209+
if strings.HasPrefix(args[2], "http") {
210+
//old APIs, ignore this field
211+
} else {
212+
toolVersion = args[2]
213+
}
209214
}
210215
if len(args) > 3 {
211-
behaviour = args[3]
216+
pack = args[3]
217+
}
218+
if len(args) > 4 {
219+
behaviour = args[4]
212220
}
213221

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

tools/download.go

+8-4
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)