Skip to content

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
Removed all references to LibraryManger.Index
  • Loading branch information
cmaglie committed Dec 27, 2023
commit f3b52c60ec25bf407ec2bb757d9a2bbea344f6a9
2 changes: 1 addition & 1 deletion commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
if !libDir.IsDir() {
// Download library
taskCallback(&rpc.TaskProgress{Name: tr("Downloading library %s", libraryRef)})
libRelease := lm.Index.FindRelease(&librariesindex.Reference{
libRelease := li.FindRelease(&librariesindex.Reference{
Name: libraryRef.Library,
Version: libraryRef.Version,
})
Expand Down
7 changes: 6 additions & 1 deletion commands/lib/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downl
return nil, err
}

li, err := instances.GetLibrariesIndex(req.GetInstance())
if err != nil {
return nil, err
}

logrus.Info("Preparing download")

lib, err := findLibraryIndexRelease(lm.Index, req)
lib, err := findLibraryIndexRelease(li, req)
if err != nil {
return nil, err
}
Expand Down
7 changes: 6 additions & 1 deletion commands/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ import (

// LibraryInstall resolves the library dependencies, then downloads and installs the libraries into the install location.
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
li, err := instances.GetLibrariesIndex(req.GetInstance())
if err != nil {
return err
}

lm, err := instances.GetLibraryManager(req.GetInstance())
if err != nil {
return err
Expand Down Expand Up @@ -72,7 +77,7 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
// Find the libReleasesToInstall to install
libReleasesToInstall := map[*librariesindex.Release]*librariesmanager.LibraryInstallPlan{}
for _, lib := range toInstall {
libRelease, err := findLibraryIndexRelease(lm.Index, &rpc.LibraryInstallRequest{
libRelease, err := findLibraryIndexRelease(li, &rpc.LibraryInstallRequest{
Name: lib.GetName(),
Version: lib.GetVersionRequired(),
})
Expand Down
13 changes: 9 additions & 4 deletions commands/lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
}
defer release()

li, err := instances.GetLibrariesIndex(req.GetInstance())
if err != nil {
return nil, err
}

lm, err := instances.GetLibraryManager(req.GetInstance())
if err != nil {
return nil, err
Expand All @@ -51,7 +56,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library

var allLibs []*installedLib
if fqbnString := req.GetFqbn(); fqbnString != "" {
allLibs = listLibraries(lm, req.GetUpdatable(), true)
allLibs = listLibraries(lm, li, req.GetUpdatable(), true)
fqbn, err := cores.ParseFQBN(req.GetFqbn())
if err != nil {
return nil, &cmderrors.InvalidFQBNError{Cause: err}
Expand Down Expand Up @@ -91,7 +96,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
allLibs = append(allLibs, lib)
}
} else {
allLibs = listLibraries(lm, req.GetUpdatable(), req.GetAll())
allLibs = listLibraries(lm, li, req.GetUpdatable(), req.GetAll())
}

installedLibs := []*rpc.InstalledLibrary{}
Expand All @@ -118,7 +123,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library

// listLibraries returns the list of installed libraries. If updatable is true it
// returns only the libraries that may be updated.
func listLibraries(lm *librariesmanager.LibrariesManager, updatable bool, all bool) []*installedLib {
func listLibraries(lm *librariesmanager.LibrariesManager, li *librariesindex.Index, updatable bool, all bool) []*installedLib {
res := []*installedLib{}
for _, libAlternatives := range lm.Libraries {
for _, lib := range libAlternatives {
Expand All @@ -127,7 +132,7 @@ func listLibraries(lm *librariesmanager.LibrariesManager, updatable bool, all bo
continue
}
}
available := lm.Index.FindLibraryUpdate(lib)
available := li.FindLibraryUpdate(lib)
if updatable && available == nil {
continue
}
Expand Down
15 changes: 10 additions & 5 deletions commands/lib/resolve_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDepe
}

// Search the requested lib
reqLibRelease, err := findLibraryIndexRelease(lm.Index, req)
li, err := instances.GetLibrariesIndex(req.GetInstance())
if err != nil {
return nil, err
}

reqLibRelease, err := findLibraryIndexRelease(li, req)
if err != nil {
return nil, err
}

// Extract all installed libraries
installedLibs := map[string]*libraries.Library{}
for _, lib := range listLibraries(lm, false, false) {
for _, lib := range listLibraries(lm, li, false, false) {
installedLibs[lib.Library.Name] = lib.Library
}

Expand All @@ -53,7 +58,7 @@ func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDepe
libs := lm.FindAllInstalled()
libs = libs.FilterByVersionAndInstallLocation(nil, libraries.User)
for _, lib := range libs {
release := lm.Index.FindRelease(&librariesindex.Reference{
release := li.FindRelease(&librariesindex.Reference{
Name: lib.Name,
Version: lib.Version,
})
Expand All @@ -62,13 +67,13 @@ func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDepe
}
}
}
deps := lm.Index.ResolveDependencies(reqLibRelease, overrides)
deps := li.ResolveDependencies(reqLibRelease, overrides)

// If no solution has been found
if len(deps) == 0 {
// Check if there is a problem with the first level deps
for _, directDep := range reqLibRelease.GetDependencies() {
if _, ok := lm.Index.Libraries[directDep.GetName()]; !ok {
if _, ok := li.Libraries[directDep.GetName()]; !ok {
err := errors.New(tr("dependency '%s' is not available", directDep.GetName()))
return nil, &cmderrors.LibraryDependenciesResolutionFailedError{Cause: err}
}
Expand Down
14 changes: 12 additions & 2 deletions commands/lib/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ import (

// LibraryUpgradeAll upgrades all the available libraries
func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
li, err := instances.GetLibrariesIndex(req.GetInstance())
if err != nil {
return err
}

lm, err := instances.GetLibraryManager(req.GetInstance())
if err != nil {
return err
}

if err := upgrade(req.GetInstance(), listLibraries(lm, true, false), downloadCB, taskCB); err != nil {
if err := upgrade(req.GetInstance(), listLibraries(lm, li, true, false), downloadCB, taskCB); err != nil {
return err
}

Expand All @@ -44,14 +49,19 @@ func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.Downloa

// LibraryUpgrade upgrades a library
func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
li, err := instances.GetLibrariesIndex(req.GetInstance())
if err != nil {
return err
}

lm, err := instances.GetLibraryManager(req.GetInstance())
if err != nil {
return err
}

// Get the library to upgrade
name := req.GetName()
lib := filterByName(listLibraries(lm, false, false), name)
lib := filterByName(listLibraries(lm, li, false, false), name)
if lib == nil {
// library not installed...
return &cmderrors.LibraryNotFoundError{Library: name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
type LibrariesManager struct {
LibrariesDir []*LibrariesDir
Libraries map[string]libraries.List `json:"libraries"`
// TODO: Fix all access to lm.Index left around
DownloadsDir *paths.Path
}

Expand Down Expand Up @@ -73,7 +72,6 @@ func NewLibraryManager(downloadsDir *paths.Path) *LibrariesManager {
return &LibrariesManager{
Libraries: map[string]libraries.List{},
DownloadsDir: downloadsDir,
Index: librariesindex.EmptyIndex,
}
}

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy