@@ -22,6 +22,7 @@ import (
22
22
"os"
23
23
"strings"
24
24
25
+ "github.com/arduino/arduino-cli/arduino"
25
26
"github.com/arduino/arduino-cli/arduino/globals"
26
27
"github.com/arduino/arduino-cli/arduino/libraries"
27
28
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
@@ -49,31 +50,42 @@ var (
49
50
// install path, where the library should be installed and the possible library that is already
50
51
// installed on the same folder and it's going to be replaced by the new one.
51
52
func (lm * LibrariesManager ) InstallPrerequisiteCheck (indexLibrary * librariesindex.Release , installLocation libraries.LibraryLocation ) (* paths.Path , * libraries.Library , error ) {
52
- var replaced * libraries.Library
53
+ installDir := lm .getLibrariesDir (installLocation )
54
+ if installDir == nil {
55
+ if installLocation == libraries .User {
56
+ return nil , nil , fmt .Errorf (tr ("User directory not set" ))
57
+ }
58
+ return nil , nil , fmt .Errorf (tr ("Builtin libraries directory not set" ))
59
+ }
60
+
53
61
name := indexLibrary .Library .Name
54
- if installedLibs , have := lm .Libraries [name ]; have {
55
- for _ , installedLib := range installedLibs {
56
- if installedLib .Location != installLocation {
57
- continue
58
- }
59
- if installedLib .Version != nil && installedLib .Version .Equal (indexLibrary .Version ) {
60
- return installedLib .InstallDir , nil , ErrAlreadyInstalled
61
- }
62
- replaced = installedLib
62
+ libs := lm .FindByReference (& librariesindex.Reference {Name : name }, installLocation )
63
+ for _ , lib := range libs {
64
+ if lib .Version != nil && lib .Version .Equal (indexLibrary .Version ) {
65
+ return lib .InstallDir , nil , ErrAlreadyInstalled
63
66
}
64
67
}
65
68
66
- libsDir := lm .getLibrariesDir (installLocation )
67
- if libsDir == nil {
68
- if installLocation == libraries .User {
69
- return nil , nil , fmt .Errorf (tr ("User directory not set" ))
69
+ if len (libs ) > 1 {
70
+ libsDir := paths .NewPathList ()
71
+ for _ , lib := range libs {
72
+ libsDir .Add (lib .InstallDir )
73
+ }
74
+ return nil , nil , & arduino.MultipleLibraryInstallDetected {
75
+ LibName : name ,
76
+ LibsDir : libsDir ,
77
+ Message : tr ("Automatic library install can't be performed in this case, please manually remove all duplicates and retry." ),
70
78
}
71
- return nil , nil , fmt .Errorf (tr ("Builtin libraries directory not set" ))
72
79
}
73
80
74
- libPath := libsDir .Join (utils .SanitizeName (indexLibrary .Library .Name ))
75
- if replaced != nil && replaced .InstallDir .EquivalentTo (libPath ) {
81
+ var replaced * libraries.Library
82
+ if len (libs ) == 1 {
83
+ replaced = libs [0 ]
84
+ }
76
85
86
+ libPath := installDir .Join (utils .SanitizeName (indexLibrary .Library .Name ))
87
+ if replaced != nil && replaced .InstallDir .EquivalentTo (libPath ) {
88
+ return libPath , replaced , nil
77
89
} else if libPath .IsDir () {
78
90
return nil , nil , fmt .Errorf (tr ("destination dir %s already exists, cannot install" ), libPath )
79
91
}
0 commit comments