Skip to content

Commit 7aecdba

Browse files
committed
report and catch a specific error when already installed
1 parent 3211746 commit 7aecdba

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

arduino/libraries/librariesmanager/install.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package librariesmanager
1919

2020
import (
21+
"errors"
2122
"fmt"
2223

2324
"github.com/arduino/arduino-cli/arduino/libraries"
@@ -26,18 +27,26 @@ import (
2627
paths "github.com/arduino/go-paths-helper"
2728
)
2829

30+
var (
31+
// ErrAlreadyInstalled is returned when a library is already installed and task
32+
// cannot proceed.
33+
ErrAlreadyInstalled = errors.New("library already installed")
34+
)
35+
2936
// InstallPrerequisiteCheck performs prequisite checks to install a library. It returns the
3037
// install path, where the library should be installed and the possible library that is already
3138
// installed on the same folder and it's going to be replaced by the new one.
3239
func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesindex.Release) (*paths.Path, *libraries.Library, error) {
40+
saneName := utils.SanitizeName(indexLibrary.Library.Name)
41+
3342
var replaced *libraries.Library
34-
if installedLibs, have := lm.Libraries[indexLibrary.Library.Name]; have {
43+
if installedLibs, have := lm.Libraries[saneName]; have {
3544
for _, installedLib := range installedLibs.Alternatives {
3645
if installedLib.Location != libraries.Sketchbook {
3746
continue
3847
}
3948
if installedLib.Version.Equal(indexLibrary.Version) {
40-
return installedLib.InstallDir, nil, fmt.Errorf("%s is already installed", indexLibrary.String())
49+
return installedLib.InstallDir, nil, ErrAlreadyInstalled
4150
}
4251
replaced = installedLib
4352
}
@@ -48,7 +57,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
4857
return nil, nil, fmt.Errorf("sketchbook directory not set")
4958
}
5059

51-
libPath := libsDir.Join(utils.SanitizeName(indexLibrary.Library.Name))
60+
libPath := libsDir.Join(saneName)
5261
if replaced != nil && replaced.InstallDir.EquivalentTo(libPath) {
5362

5463
} else if libPath.IsDir() {

commands/lib/install.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,23 @@ func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *libraries
5858
taskCB(&rpc.TaskProgress{Name: "Installing " + libRelease.String()})
5959
logrus.WithField("library", libRelease).Info("Installing library")
6060
libPath, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease)
61+
if err == librariesmanager.ErrAlreadyInstalled {
62+
taskCB(&rpc.TaskProgress{Message: "Alredy installed " + libRelease.String(), Completed: true})
63+
return nil
64+
}
65+
6166
if err != nil {
6267
return fmt.Errorf("checking lib install prerequisites: %s", err)
6368
}
69+
6470
if libReplaced != nil {
6571
taskCB(&rpc.TaskProgress{Message: fmt.Sprintf("Replacing %s with %s", libReplaced, libRelease)})
6672
}
73+
6774
if err := lm.Install(libRelease, libPath); err != nil {
6875
return err
6976
}
70-
taskCB(&rpc.TaskProgress{Message: "Installed " + libRelease.String(), Completed: true})
7177

78+
taskCB(&rpc.TaskProgress{Message: "Installed " + libRelease.String(), Completed: true})
7279
return nil
7380
}

0 commit comments

Comments
 (0)