4949// install path, where the library should be installed and the possible library that is already
5050// installed on the same folder and it's going to be replaced by the new one.
5151func (lm * LibrariesManager ) InstallPrerequisiteCheck (indexLibrary * librariesindex.Release , installLocation libraries.LibraryLocation ) (* paths.Path , * libraries.Library , error ) {
52- saneName := utils .SanitizeName (indexLibrary .Library .Name )
53-
5452 var replaced * libraries.Library
55- if installedLibs , have := lm .Libraries [saneName ]; have {
53+ name := indexLibrary .Library .Name
54+ if installedLibs , have := lm .Libraries [name ]; have {
5655 for _ , installedLib := range installedLibs {
5756 if installedLib .Location != installLocation {
5857 continue
@@ -72,7 +71,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
7271 return nil , nil , fmt .Errorf (tr ("Builtin libraries directory not set" ))
7372 }
7473
75- libPath := libsDir .Join (saneName )
74+ libPath := libsDir .Join (utils . SanitizeName ( indexLibrary . Library . Name ) )
7675 if replaced != nil && replaced .InstallDir .EquivalentTo (libPath ) {
7776
7877 } else if libPath .IsDir () {
@@ -99,9 +98,9 @@ func (lm *LibrariesManager) Uninstall(lib *libraries.Library) error {
9998 return fmt .Errorf (tr ("removing lib directory: %s" ), err )
10099 }
101100
102- alternatives := lm .Libraries [lib .Name ]
101+ alternatives := lm .Libraries [lib .RealName ]
103102 alternatives .Remove (lib )
104- lm .Libraries [lib .Name ] = alternatives
103+ lm .Libraries [lib .RealName ] = alternatives
105104 return nil
106105}
107106
@@ -191,8 +190,8 @@ func (lm *LibrariesManager) InstallZipLib(ctx context.Context, archivePath strin
191190
192191// InstallGitLib installs a library hosted on a git repository on the specified path.
193192func (lm * LibrariesManager ) InstallGitLib (gitURL string , overwrite bool ) error {
194- libsDir := lm .getLibrariesDir (libraries .User )
195- if libsDir == nil {
193+ installDir := lm .getLibrariesDir (libraries .User )
194+ if installDir == nil {
196195 return fmt .Errorf (tr ("User directory not set" ))
197196 }
198197
@@ -204,10 +203,9 @@ func (lm *LibrariesManager) InstallGitLib(gitURL string, overwrite bool) error {
204203 return err
205204 }
206205
207- installPath := libsDir .Join (libraryName )
208-
209206 // Deletes libraries folder if already installed
210- if _ , ok := lm .Libraries [libraryName ]; ok {
207+ installPath := installDir .Join (libraryName )
208+ if installPath .IsDir () {
211209 if ! overwrite {
212210 return fmt .Errorf (tr ("library %s already installed" ), libraryName )
213211 }
@@ -217,6 +215,9 @@ func (lm *LibrariesManager) InstallGitLib(gitURL string, overwrite bool) error {
217215 Trace ("Deleting library" )
218216 installPath .RemoveAll ()
219217 }
218+ if installPath .Exist () {
219+ return fmt .Errorf (tr ("could not create directory %s: a file with the same name exists!" , installPath ))
220+ }
220221
221222 logrus .
222223 WithField ("library name" , libraryName ).
0 commit comments