@@ -39,40 +39,10 @@ import (
3939 "golang.org/x/crypto/openpgp"
4040
4141 "github.com/arduino/arduino-create-agent/utilities"
42+ "github.com/arduino/arduino-create-agent/v2/pkgs"
4243 "github.com/blang/semver"
43- "github.com/xrash/smetrics"
4444)
4545
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-
7646// public vars to allow override in the tests
7747var (
7848 OS = runtime .GOOS
@@ -198,7 +168,7 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
198168 return err
199169 }
200170
201- var data index
171+ var data pkgs. Index
202172 json .Unmarshal (body , & data )
203173
204174 // Find the tool by name
@@ -244,7 +214,7 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
244214 checksum := sha256 .Sum256 (body )
245215 checkSumString := "SHA-256:" + hex .EncodeToString (checksum [:sha256 .Size ])
246216
247- if checkSumString != correctSystem .CheckSum {
217+ if checkSumString != correctSystem .Checksum {
248218 return errors .New ("checksum doesn't match" )
249219 }
250220
@@ -298,8 +268,8 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
298268 return t .writeMap ()
299269}
300270
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
303273 correctTool .Version = "0.0"
304274
305275 for _ , p := range data .Packages {
@@ -323,16 +293,7 @@ func findTool(pack, name, version string, data index) (tool, system) {
323293 }
324294
325295 // 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 )
336297
337298 return correctTool , correctSystem
338299}
0 commit comments