From cc10dc92d79738e183c05a0507424515107fe147 Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Fri, 7 Oct 2016 10:06:30 +0200 Subject: [PATCH 1/2] Find the tool given the packager --- hub.go | 10 +++++++--- tools/download.go | 12 ++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/hub.go b/hub.go index 17363e48f..faa6baeac 100755 --- a/hub.go +++ b/hub.go @@ -192,8 +192,9 @@ func checkCmd(m []byte) { } else if strings.HasPrefix(sl, "downloadtool") { go func() { args := strings.Split(s, " ") - var tool, toolVersion, behaviour string + var tool, toolVersion, pack, behaviour string toolVersion = "latest" + pack = "arduino" behaviour = "keep" if len(args) <= 1 { mapD := map[string]string{"DownloadStatus": "Error", "Msg": "Not enough arguments"} @@ -208,10 +209,13 @@ func checkCmd(m []byte) { toolVersion = args[2] } if len(args) > 3 { - behaviour = args[3] + pack = args[3] + } + if len(args) > 4 { + behaviour = args[4] } - err := Tools.Download(tool, toolVersion, behaviour) + err := Tools.Download(pack, tool, toolVersion, behaviour) if err != nil { mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()} mapB, _ := json.Marshal(mapD) diff --git a/tools/download.go b/tools/download.go index 0d9330bce..e5262a694 100644 --- a/tools/download.go +++ b/tools/download.go @@ -130,6 +130,7 @@ func (t *Tools) DownloadPackageIndex(index_file, signature_file string) error { // It will extract it in a folder in .arduino-create, and it will update the // Installed map. // +// pack contains the packager of the tool // name contains the name of the tool. // version contains the version of the tool. // 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 { // If version is not "latest" and behaviour is "replace", it will download the // version again. If instead behaviour is "keep" it will not download the version // if it already exists. -func (t *Tools) Download(name, version, behaviour string) error { +func (t *Tools) Download(pack, name, version, behaviour string) error { index_file := path.Join(t.Directory, "package_index.json") signature_file := path.Join(t.Directory, "package_index.json.sig") @@ -169,10 +170,10 @@ func (t *Tools) Download(name, version, behaviour string) error { t.Logger.Println(string(body)) // Find the tool by name - correctTool, correctSystem := findTool(name, version, data) + correctTool, correctSystem := findTool(pack, name, version, data) if correctTool.Name == "" || correctSystem.URL == "" { - t.Logger.Println("We couldn't find a tool with the name " + name + " and version " + version) + t.Logger.Println("We couldn't find a tool with the name " + name + " and version " + version + " packaged by " + pack) return nil } @@ -255,11 +256,14 @@ func (t *Tools) Download(name, version, behaviour string) error { return t.writeMap() } -func findTool(name, version string, data index) (tool, system) { +func findTool(pack, name, version string, data index) (tool, system) { var correctTool tool correctTool.Version = "0.0" for _, p := range data.Packages { + if p.Name != pack { + continue + } for _, t := range p.Tools { if version != "latest" { if t.Name == name && t.Version == version { From 00f636ded640b4c36d67db9013e03f6961e79e6d Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Fri, 7 Oct 2016 10:16:48 +0200 Subject: [PATCH 2/2] Ignore old apis --- hub.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hub.go b/hub.go index faa6baeac..36b1c5fba 100755 --- a/hub.go +++ b/hub.go @@ -206,7 +206,11 @@ func checkCmd(m []byte) { tool = args[1] } if len(args) > 2 { - toolVersion = args[2] + if strings.HasPrefix(args[2], "http") { + //old APIs, ignore this field + } else { + toolVersion = args[2] + } } if len(args) > 3 { pack = args[3]