@@ -22,6 +22,7 @@ import (
2222 "os"
2323 "strings"
2424
25+ "github.com/arduino/arduino-cli/arduino"
2526 "github.com/arduino/arduino-cli/arduino/globals"
2627 "github.com/arduino/arduino-cli/arduino/libraries"
2728 "github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
@@ -49,31 +50,42 @@ var (
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.
5152func (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+
5361 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
6366 }
6467 }
6568
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." ),
7078 }
71- return nil , nil , fmt .Errorf (tr ("Builtin libraries directory not set" ))
7279 }
7380
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+ }
7685
86+ libPath := installDir .Join (utils .SanitizeName (indexLibrary .Library .Name ))
87+ if replaced != nil && replaced .InstallDir .EquivalentTo (libPath ) {
88+ return libPath , replaced , nil
7789 } else if libPath .IsDir () {
7890 return nil , nil , fmt .Errorf (tr ("destination dir %s already exists, cannot install" ), libPath )
7991 }
0 commit comments