@@ -20,9 +20,11 @@ import (
2020 "fmt"
2121 "runtime"
2222
23+ "github.com/arduino/arduino-cli/arduino"
2324 "github.com/arduino/arduino-cli/arduino/cores"
2425 "github.com/arduino/arduino-cli/arduino/cores/packageindex"
2526 "github.com/arduino/arduino-cli/executils"
27+ rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2628 "github.com/arduino/go-paths-helper"
2729 "github.com/pkg/errors"
2830)
@@ -127,7 +129,18 @@ func (pm *PackageManager) UninstallPlatform(platformRelease *cores.PlatformRelea
127129}
128130
129131// InstallTool installs a specific release of a tool.
130- func (pm * PackageManager ) InstallTool (toolRelease * cores.ToolRelease ) error {
132+ func (pm * PackageManager ) InstallTool (toolRelease * cores.ToolRelease , taskCB rpc.TaskProgressCB ) error {
133+ log := pm .Log .WithField ("Tool" , toolRelease )
134+
135+ if toolRelease .IsInstalled () {
136+ log .Warn ("Tool already installed" )
137+ taskCB (& rpc.TaskProgress {Name : tr ("Tool %s already installed" , toolRelease ), Completed : true })
138+ return nil
139+ }
140+
141+ log .Info ("Installing tool" )
142+ taskCB (& rpc.TaskProgress {Name : tr ("Installing %s" , toolRelease )})
143+
131144 toolResource := toolRelease .GetCompatibleFlavour ()
132145 if toolResource == nil {
133146 return fmt .Errorf (tr ("no compatible version of %s tools found for the current os" ), toolRelease .Tool .Name )
@@ -137,7 +150,15 @@ func (pm *PackageManager) InstallTool(toolRelease *cores.ToolRelease) error {
137150 "tools" ,
138151 toolRelease .Tool .Name ,
139152 toolRelease .Version .String ())
140- return toolResource .Install (pm .DownloadDir , pm .tempDir , destDir )
153+ err := toolResource .Install (pm .DownloadDir , pm .tempDir , destDir )
154+ if err != nil {
155+ log .WithError (err ).Warn ("Cannot install tool" )
156+ return & arduino.FailedInstallError {Message : tr ("Cannot install tool %s" , toolRelease ), Cause : err }
157+ }
158+ log .Info ("Tool installed" )
159+ taskCB (& rpc.TaskProgress {Message : tr ("%s installed" , toolRelease ), Completed : true })
160+
161+ return nil
141162}
142163
143164// IsManagedToolRelease returns true if the ToolRelease is managed by the PackageManager
0 commit comments