@@ -39,40 +39,10 @@ import (
39
39
"golang.org/x/crypto/openpgp"
40
40
41
41
"github.com/arduino/arduino-create-agent/utilities"
42
+ "github.com/arduino/arduino-create-agent/v2/pkgs"
42
43
"github.com/blang/semver"
43
- "github.com/xrash/smetrics"
44
44
)
45
45
46
- type system struct {
47
- Host string `json:"host"`
48
- URL string `json:"url"`
49
- Name string `json:"archiveFileName"`
50
- CheckSum string `json:"checksum"`
51
- }
52
-
53
- type tool struct {
54
- Name string `json:"name"`
55
- Version string `json:"version"`
56
- Systems []system `json:"systems"`
57
- }
58
-
59
- type index struct {
60
- Packages []struct {
61
- Name string `json:"name"`
62
- Tools []tool `json:"tools"`
63
- } `json:"packages"`
64
- }
65
-
66
- var systems = map [string ]string {
67
- "linuxamd64" : "x86_64-linux-gnu" ,
68
- "linux386" : "i686-linux-gnu" ,
69
- "darwinamd64" : "i686-apple-darwin" ,
70
- "darwinarm64" : "arm64-apple-darwin" ,
71
- "windows386" : "i686-mingw32" ,
72
- "windowsamd64" : "i686-mingw32" ,
73
- "linuxarm" : "arm-linux-gnueabihf" ,
74
- }
75
-
76
46
// public vars to allow override in the tests
77
47
var (
78
48
OS = runtime .GOOS
@@ -198,7 +168,7 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
198
168
return err
199
169
}
200
170
201
- var data index
171
+ var data pkgs. Index
202
172
json .Unmarshal (body , & data )
203
173
204
174
// Find the tool by name
@@ -244,7 +214,7 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
244
214
checksum := sha256 .Sum256 (body )
245
215
checkSumString := "SHA-256:" + hex .EncodeToString (checksum [:sha256 .Size ])
246
216
247
- if checkSumString != correctSystem .CheckSum {
217
+ if checkSumString != correctSystem .Checksum {
248
218
return errors .New ("checksum doesn't match" )
249
219
}
250
220
@@ -298,8 +268,8 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
298
268
return t .writeMap ()
299
269
}
300
270
301
- func findTool (pack , name , version string , data index ) (tool , system ) {
302
- var correctTool tool
271
+ func findTool (pack , name , version string , data pkgs. Index ) (pkgs. Tool , pkgs. System ) {
272
+ var correctTool pkgs. Tool
303
273
correctTool .Version = "0.0"
304
274
305
275
for _ , p := range data .Packages {
@@ -323,16 +293,7 @@ func findTool(pack, name, version string, data index) (tool, system) {
323
293
}
324
294
325
295
// Find the url based on system
326
- var correctSystem system
327
- maxSimilarity := 0.7
328
-
329
- for _ , s := range correctTool .Systems {
330
- similarity := smetrics .Jaro (s .Host , systems [OS + Arch ])
331
- if similarity > maxSimilarity {
332
- correctSystem = s
333
- maxSimilarity = similarity
334
- }
335
- }
296
+ correctSystem := correctTool .GetFlavourCompatibleWith (OS , Arch )
336
297
337
298
return correctTool , correctSystem
338
299
}
0 commit comments