Skip to content

Commit

Permalink
Include the v2.Tools constructor in the old Tools struct
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoPologruto committed Aug 5, 2024
1 parent 1a36a2b commit 650622b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tools/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/arduino/arduino-create-agent/gen/tools"
"github.com/arduino/arduino-create-agent/utilities"
"github.com/arduino/arduino-create-agent/v2/pkgs"
)

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

tool := pkgs.New(t.index, t.directory.String(), behaviour)
_, err := tool.Install(context.Background(), &tools.ToolPayload{Name: name, Version: version, Packager: pack})
t.tools.SetBehaviour(behaviour)
_, err := t.tools.Install(context.Background(), &tools.ToolPayload{Name: name, Version: version, Packager: pack})
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sync"

"github.com/arduino/arduino-create-agent/index"
"github.com/arduino/arduino-create-agent/v2/pkgs"
"github.com/arduino/go-paths-helper"
"github.com/xrash/smetrics"
)
Expand All @@ -47,6 +48,7 @@ type Tools struct {
logger func(msg string)
installed map[string]string
mutex sync.RWMutex
tools *pkgs.Tools
}

// New will return a Tool object, allowing the caller to execute operations on it.
Expand All @@ -60,6 +62,7 @@ func New(directory *paths.Path, index *index.Resource, logger func(msg string))
logger: logger,
installed: map[string]string{},
mutex: sync.RWMutex{},
tools: pkgs.New(index, directory.String(), "replace"),
}
_ = t.readMap()
return t
Expand Down
5 changes: 5 additions & 0 deletions v2/pkgs/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ func (t *Tools) writeInstalled(path string) error {
return os.WriteFile(installedFile, data, 0644)
}

// SetBehaviour sets the download behaviour to either keep or replace
func (t *Tools) SetBehaviour(behaviour string) {
t.behaviour = behaviour
}

func pathExists(path string) bool {
_, err := os.Stat(path)
if err == nil {
Expand Down

0 comments on commit 650622b

Please sign in to comment.