Skip to content

Commit f7b0e61

Browse files
committed
Merged downloadTool with the proper packagamanger method
1 parent 895b357 commit f7b0e61

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

arduino/cores/packagemanager/download.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/arduino/arduino-cli/arduino"
2222
"github.com/arduino/arduino-cli/arduino/cores"
2323
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
24+
"github.com/pkg/errors"
2425
"go.bug.st/downloader/v2"
2526
semver "go.bug.st/relaxed-semver"
2627
)
@@ -122,9 +123,16 @@ func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReferenc
122123
func (pm *PackageManager) DownloadToolRelease(tool *cores.ToolRelease, config *downloader.Config, progressCB rpc.DownloadProgressCB) error {
123124
resource := tool.GetCompatibleFlavour()
124125
if resource == nil {
125-
return fmt.Errorf(tr("tool not available for your OS"))
126+
return &arduino.FailedDownloadError{
127+
Message: tr("Error downloading tool %s", tool),
128+
Cause: errors.New(tr("no versions available for the current OS", tool))}
126129
}
127-
return resource.Download(pm.DownloadDir, config, tool.String(), progressCB)
130+
if err := resource.Download(pm.DownloadDir, config, tool.String(), progressCB); err != nil {
131+
return &arduino.FailedDownloadError{
132+
Message: tr("Error downloading tool %s", tool),
133+
Cause: err}
134+
}
135+
return nil
128136
}
129137

130138
// DownloadPlatformRelease downloads a PlatformRelease. If the platform is already downloaded a

commands/core/download.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package core
1717

1818
import (
1919
"context"
20-
"errors"
2120

2221
"github.com/arduino/arduino-cli/arduino"
2322
"github.com/arduino/arduino-cli/arduino/cores"
@@ -57,7 +56,7 @@ func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadRequest, dow
5756
}
5857

5958
for _, tool := range tools {
60-
if err := downloadTool(pm, tool, downloadCB); err != nil {
59+
if err := pm.DownloadToolRelease(tool, nil, downloadCB); err != nil {
6160
return nil, err
6261
}
6362
}
@@ -73,18 +72,3 @@ func downloadPlatform(pm *packagemanager.PackageManager, platformRelease *cores.
7372
}
7473
return pm.DownloadPlatformRelease(platformRelease, config, downloadCB)
7574
}
76-
77-
func downloadTool(pm *packagemanager.PackageManager, tool *cores.ToolRelease, downloadCB rpc.DownloadProgressCB) error {
78-
// Check if tool has a flavor available for the current OS
79-
if tool.GetCompatibleFlavour() == nil {
80-
return &arduino.FailedDownloadError{
81-
Message: tr("Error downloading tool %s", tool),
82-
Cause: errors.New(tr("no versions available for the current OS", tool))}
83-
}
84-
85-
if err := pm.DownloadToolRelease(tool, nil, downloadCB); err != nil {
86-
return &arduino.FailedDownloadError{Message: tr("Error downloading tool %s", tool), Cause: err}
87-
}
88-
89-
return nil
90-
}

commands/core/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func installPlatform(pm *packagemanager.PackageManager,
9595
// Package download
9696
taskCB(&rpc.TaskProgress{Name: tr("Downloading packages")})
9797
for _, tool := range toolsToInstall {
98-
if err := downloadTool(pm, tool, downloadCB); err != nil {
98+
if err := pm.DownloadToolRelease(tool, nil, downloadCB); err != nil {
9999
return err
100100
}
101101
}

0 commit comments

Comments
 (0)