18
18
package librariesmanager
19
19
20
20
import (
21
+ "errors"
21
22
"fmt"
22
23
23
24
"github.com/arduino/arduino-cli/arduino/libraries"
@@ -26,18 +27,26 @@ import (
26
27
paths "github.com/arduino/go-paths-helper"
27
28
)
28
29
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
+
29
36
// InstallPrerequisiteCheck performs prequisite checks to install a library. It returns the
30
37
// install path, where the library should be installed and the possible library that is already
31
38
// installed on the same folder and it's going to be replaced by the new one.
32
39
func (lm * LibrariesManager ) InstallPrerequisiteCheck (indexLibrary * librariesindex.Release ) (* paths.Path , * libraries.Library , error ) {
40
+ saneName := utils .SanitizeName (indexLibrary .Library .Name )
41
+
33
42
var replaced * libraries.Library
34
- if installedLibs , have := lm .Libraries [indexLibrary . Library . Name ]; have {
43
+ if installedLibs , have := lm .Libraries [saneName ]; have {
35
44
for _ , installedLib := range installedLibs .Alternatives {
36
45
if installedLib .Location != libraries .Sketchbook {
37
46
continue
38
47
}
39
48
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
41
50
}
42
51
replaced = installedLib
43
52
}
@@ -48,7 +57,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
48
57
return nil , nil , fmt .Errorf ("sketchbook directory not set" )
49
58
}
50
59
51
- libPath := libsDir .Join (utils . SanitizeName ( indexLibrary . Library . Name ) )
60
+ libPath := libsDir .Join (saneName )
52
61
if replaced != nil && replaced .InstallDir .EquivalentTo (libPath ) {
53
62
54
63
} else if libPath .IsDir () {
0 commit comments