Skip to content

[breaking] Downloaders/Installers refactor #1809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merged downloadTool with the proper packagamanger method
  • Loading branch information
cmaglie committed Aug 5, 2022
commit f7b0e61103b073d7f94534747495a413dbe2f659
12 changes: 10 additions & 2 deletions arduino/cores/packagemanager/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/cores"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/pkg/errors"
"go.bug.st/downloader/v2"
semver "go.bug.st/relaxed-semver"
)
Expand Down Expand Up @@ -122,9 +123,16 @@ func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReferenc
func (pm *PackageManager) DownloadToolRelease(tool *cores.ToolRelease, config *downloader.Config, progressCB rpc.DownloadProgressCB) error {
resource := tool.GetCompatibleFlavour()
if resource == nil {
return fmt.Errorf(tr("tool not available for your OS"))
return &arduino.FailedDownloadError{
Message: tr("Error downloading tool %s", tool),
Cause: errors.New(tr("no versions available for the current OS", tool))}
}
return resource.Download(pm.DownloadDir, config, tool.String(), progressCB)
if err := resource.Download(pm.DownloadDir, config, tool.String(), progressCB); err != nil {
return &arduino.FailedDownloadError{
Message: tr("Error downloading tool %s", tool),
Cause: err}
}
return nil
}

// DownloadPlatformRelease downloads a PlatformRelease. If the platform is already downloaded a
Expand Down
18 changes: 1 addition & 17 deletions commands/core/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package core

import (
"context"
"errors"

"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/cores"
Expand Down Expand Up @@ -57,7 +56,7 @@ func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadRequest, dow
}

for _, tool := range tools {
if err := downloadTool(pm, tool, downloadCB); err != nil {
if err := pm.DownloadToolRelease(tool, nil, downloadCB); err != nil {
return nil, err
}
}
Expand All @@ -73,18 +72,3 @@ func downloadPlatform(pm *packagemanager.PackageManager, platformRelease *cores.
}
return pm.DownloadPlatformRelease(platformRelease, config, downloadCB)
}

func downloadTool(pm *packagemanager.PackageManager, tool *cores.ToolRelease, downloadCB rpc.DownloadProgressCB) error {
// Check if tool has a flavor available for the current OS
if tool.GetCompatibleFlavour() == nil {
return &arduino.FailedDownloadError{
Message: tr("Error downloading tool %s", tool),
Cause: errors.New(tr("no versions available for the current OS", tool))}
}

if err := pm.DownloadToolRelease(tool, nil, downloadCB); err != nil {
return &arduino.FailedDownloadError{Message: tr("Error downloading tool %s", tool), Cause: err}
}

return nil
}
2 changes: 1 addition & 1 deletion commands/core/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func installPlatform(pm *packagemanager.PackageManager,
// Package download
taskCB(&rpc.TaskProgress{Name: tr("Downloading packages")})
for _, tool := range toolsToInstall {
if err := downloadTool(pm, tool, downloadCB); err != nil {
if err := pm.DownloadToolRelease(tool, nil, downloadCB); err != nil {
return err
}
}
Expand Down