Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix concurrent access to libraries manager gRPC functions. #2480

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 14 commits into from
Jan 2, 2024
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
downloadLibrary do not require a libmanager but just the downloadDir
  • Loading branch information
cmaglie committed Dec 27, 2023
commit 39f156748c3a7ebc5438aae916a0d769f564b7e9
15 changes: 9 additions & 6 deletions 15 commands/lib/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"github.com/arduino/arduino-cli/commands/internal/instances"
"github.com/arduino/arduino-cli/internal/arduino/httpclient"
"github.com/arduino/arduino-cli/internal/arduino/libraries/librariesindex"
"github.com/arduino/arduino-cli/internal/arduino/libraries/librariesmanager"
"github.com/arduino/arduino-cli/internal/i18n"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
)

Expand All @@ -35,9 +35,12 @@ var tr = i18n.Tr
func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.LibraryDownloadResponse, error) {
logrus.Info("Executing `arduino-cli lib download`")

lm, err := instances.GetLibraryManager(req.GetInstance())
if err != nil {
var downloadsDir *paths.Path
if pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()); err != nil {
return nil, err
} else {
downloadsDir = pme.DownloadDir
release()
}

li, err := instances.GetLibrariesIndex(req.GetInstance())
Expand All @@ -52,22 +55,22 @@ func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downl
return nil, err
}

if err := downloadLibrary(lm, lib, downloadCB, func(*rpc.TaskProgress) {}, "download"); err != nil {
if err := downloadLibrary(downloadsDir, lib, downloadCB, func(*rpc.TaskProgress) {}, "download"); err != nil {
return nil, err
}

return &rpc.LibraryDownloadResponse{}, nil
}

func downloadLibrary(lm *librariesmanager.LibrariesManager, libRelease *librariesindex.Release,
func downloadLibrary(downloadsDir *paths.Path, libRelease *librariesindex.Release,
downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB, queryParameter string) error {

taskCB(&rpc.TaskProgress{Name: tr("Downloading %s", libRelease)})
config, err := httpclient.GetDownloaderConfig()
if err != nil {
return &cmderrors.FailedDownloadError{Message: tr("Can't download library"), Cause: err}
}
if err := libRelease.Resource.Download(lm.DownloadsDir, config, libRelease.String(), downloadCB, queryParameter); err != nil {
if err := libRelease.Resource.Download(downloadsDir, config, libRelease.String(), downloadCB, queryParameter); err != nil {
return &cmderrors.FailedDownloadError{Message: tr("Can't download library"), Cause: err}
}
taskCB(&rpc.TaskProgress{Completed: true})
Expand Down
11 changes: 10 additions & 1 deletion 11 commands/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
}
}

// Obtain the download directory
var downloadsDir *paths.Path
if pme, releasePme, err := instances.GetPackageManagerExplorer(req.GetInstance()); err != nil {
return err
} else {
downloadsDir = pme.DownloadDir
releasePme()
}

// Find the libReleasesToInstall to install
libReleasesToInstall := map[*librariesindex.Release]*librariesmanager.LibraryInstallPlan{}
for _, lib := range toInstall {
Expand Down Expand Up @@ -114,7 +123,7 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
downloadReason += "-builtin"
}
}
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, downloadReason); err != nil {
if err := downloadLibrary(downloadsDir, libRelease, downloadCB, taskCB, downloadReason); err != nil {
return err
}
if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.