@@ -17,19 +17,29 @@ import (
17
17
18
18
"github.com/arduino/arduino-create-agent/gen/tools"
19
19
"github.com/codeclysm/extract"
20
- "github.com/sirupsen/logrus"
21
20
"github.com/xrash/smetrics"
22
21
)
23
22
23
+ // Tools is a client that implements github.com/arduino/arduino-create-agent/gen/tools.Service interface.
24
+ // It saves tools in a specified folder with this structure: packager/name/version
25
+ // For example:
26
+ // folder
27
+ // └── arduino
28
+ // └── bossac
29
+ // ├── 1.6.1-arduino
30
+ // │ └── bossac
31
+ // └── 1.7.0
32
+ // └── bossac
33
+ // It requires an Indexes client to list and read package index files: use the Indexes struct
24
34
type Tools struct {
25
- Log * logrus.Logger
26
35
Indexes interface {
27
36
List (context.Context ) ([]string , error )
28
37
Get (context.Context , string ) (Index , error )
29
38
}
30
39
Folder string
31
40
}
32
41
42
+ // Available crawles the downloaded package index files and returns a list of tools that can be installed.
33
43
func (c * Tools ) Available (ctx context.Context ) (res tools.ToolCollection , err error ) {
34
44
list , err := c .Indexes .List (ctx )
35
45
if err != nil {
@@ -56,6 +66,7 @@ func (c *Tools) Available(ctx context.Context) (res tools.ToolCollection, err er
56
66
return res , nil
57
67
}
58
68
69
+ // Installed crawles the Tools Folder and finds the installed tools.
59
70
func (c * Tools ) Installed (ctx context.Context ) (tools.ToolCollection , error ) {
60
71
res := tools.ToolCollection {}
61
72
@@ -94,6 +105,8 @@ func (c *Tools) Installed(ctx context.Context) (tools.ToolCollection, error) {
94
105
return res , nil
95
106
}
96
107
108
+ // Install crawles the Index folder, downloads the specified tool, extracts the archive in the Tools Folder.
109
+ // It checks for the Signature specified in the package index.
97
110
func (c * Tools ) Install (ctx context.Context , payload * tools.ToolPayload ) error {
98
111
list , err := c .Indexes .List (ctx )
99
112
if err != nil {
@@ -157,6 +170,7 @@ func (c *Tools) install(ctx context.Context, packager string, tool Tool) error {
157
170
return nil
158
171
}
159
172
173
+ // Remove deletes the tool folder from Tools Folder
160
174
func (c * Tools ) Remove (ctx context.Context , payload * tools.ToolPayload ) error {
161
175
path := filepath .Join (payload .Packager , payload .Name , payload .Version )
162
176
0 commit comments