Skip to content

Commit d5c9c98

Browse files
committed
librariesmanager.InstallPrerequisiteCheck signature change
It now accepts library name and version as single arguments since we are going to use this function also for libraries not present in the index.
1 parent 58a8ccf commit d5c9c98

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

arduino/libraries/librariesmanager/install.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/arduino/arduino-cli/arduino/utils"
3030
paths "github.com/arduino/go-paths-helper"
3131
"github.com/codeclysm/extract/v3"
32+
semver "go.bug.st/relaxed-semver"
3233
"gopkg.in/src-d/go-git.v4"
3334
"gopkg.in/src-d/go-git.v4/plumbing"
3435
)
@@ -48,7 +49,7 @@ var (
4849
// InstallPrerequisiteCheck performs prequisite checks to install a library. It returns the
4950
// install path, where the library should be installed and the possible library that is already
5051
// installed on the same folder and it's going to be replaced by the new one.
51-
func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesindex.Release, installLocation libraries.LibraryLocation) (*paths.Path, *libraries.Library, error) {
52+
func (lm *LibrariesManager) InstallPrerequisiteCheck(name string, version *semver.Version, installLocation libraries.LibraryLocation) (*paths.Path, *libraries.Library, error) {
5253
installDir := lm.getLibrariesDir(installLocation)
5354
if installDir == nil {
5455
if installLocation == libraries.User {
@@ -57,10 +58,9 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
5758
return nil, nil, fmt.Errorf(tr("Builtin libraries directory not set"))
5859
}
5960

60-
name := indexLibrary.Library.Name
6161
libs := lm.FindByReference(&librariesindex.Reference{Name: name}, installLocation)
6262
for _, lib := range libs {
63-
if lib.Version != nil && lib.Version.Equal(indexLibrary.Version) {
63+
if lib.Version != nil && lib.Version.Equal(version) {
6464
return lib.InstallDir, nil, ErrAlreadyInstalled
6565
}
6666
}
@@ -82,7 +82,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
8282
replaced = libs[0]
8383
}
8484

85-
libPath := installDir.Join(utils.SanitizeName(indexLibrary.Library.Name))
85+
libPath := installDir.Join(utils.SanitizeName(name))
8686
if replaced != nil && replaced.InstallDir.EquivalentTo(libPath) {
8787
return libPath, replaced, nil
8888
} else if libPath.IsDir() {

commands/lib/install.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
8282
// Check if any of the libraries to install is already installed and remove it from the list
8383
j := 0
8484
for i, libRelease := range libReleasesToInstall {
85-
_, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease, installLocation)
85+
_, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease.Library.Name, libRelease.Version, installLocation)
8686
if errors.Is(err, librariesmanager.ErrAlreadyInstalled) {
8787
taskCB(&rpc.TaskProgress{Message: tr("Already installed %s", libRelease), Completed: true})
8888
} else if err != nil {
@@ -127,7 +127,7 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
127127
func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *librariesindex.Release, installLocation libraries.LibraryLocation, taskCB rpc.TaskProgressCB) error {
128128
taskCB(&rpc.TaskProgress{Name: tr("Installing %s", libRelease)})
129129
logrus.WithField("library", libRelease).Info("Installing library")
130-
libPath, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease, installLocation)
130+
libPath, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease.Library.Name, libRelease.Version, installLocation)
131131
if errors.Is(err, librariesmanager.ErrAlreadyInstalled) {
132132
taskCB(&rpc.TaskProgress{Message: tr("Already installed %s", libRelease), Completed: true})
133133
return err

0 commit comments

Comments
 (0)