Skip to content

Commit 2e988ee

Browse files
Include the v2.Tools constructor in the old Tools struct
1 parent 33c4d94 commit 2e988ee

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

tools/download.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
"github.com/arduino/arduino-create-agent/gen/tools"
2727
"github.com/arduino/arduino-create-agent/utilities"
28-
"github.com/arduino/arduino-create-agent/v2/pkgs"
2928
)
3029

3130
// Download will parse the index at the indexURL for the tool to download.
@@ -45,8 +44,8 @@ import (
4544
// if it already exists.
4645
func (t *Tools) Download(pack, name, version, behaviour string) error {
4746

48-
tool := pkgs.New(t.index, t.directory.String(), behaviour)
49-
_, err := tool.Install(context.Background(), &tools.ToolPayload{Name: name, Version: version, Packager: pack})
47+
t.tools.SetBehaviour(behaviour)
48+
_, err := t.tools.Install(context.Background(), &tools.ToolPayload{Name: name, Version: version, Packager: pack})
5049
if err != nil {
5150
return err
5251
}

tools/tools.go

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"sync"
2323

2424
"github.com/arduino/arduino-create-agent/index"
25+
"github.com/arduino/arduino-create-agent/v2/pkgs"
2526
"github.com/arduino/go-paths-helper"
2627
"github.com/xrash/smetrics"
2728
)
@@ -47,6 +48,7 @@ type Tools struct {
4748
logger func(msg string)
4849
installed map[string]string
4950
mutex sync.RWMutex
51+
tools *pkgs.Tools
5052
}
5153

5254
// New will return a Tool object, allowing the caller to execute operations on it.
@@ -60,6 +62,7 @@ func New(directory *paths.Path, index *index.Resource, logger func(msg string))
6062
logger: logger,
6163
installed: map[string]string{},
6264
mutex: sync.RWMutex{},
65+
tools: pkgs.New(index, directory.String(), "replace"),
6366
}
6467
_ = t.readMap()
6568
return t

v2/pkgs/tools.go

+5
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ func (t *Tools) writeInstalled(path string) error {
327327
return os.WriteFile(installedFile, data, 0644)
328328
}
329329

330+
// SetBehaviour sets the download behaviour to either keep or replace
331+
func (t *Tools) SetBehaviour(behaviour string) {
332+
t.behaviour = behaviour
333+
}
334+
330335
func pathExists(path string) bool {
331336
_, err := os.Stat(path)
332337
if err == nil {

0 commit comments

Comments
 (0)