1818package librariesmanager
1919
2020import (
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.
3239func (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 () {
0 commit comments