49
49
// install path, where the library should be installed and the possible library that is already
50
50
// installed on the same folder and it's going to be replaced by the new one.
51
51
func (lm * LibrariesManager ) InstallPrerequisiteCheck (indexLibrary * librariesindex.Release , installLocation libraries.LibraryLocation ) (* paths.Path , * libraries.Library , error ) {
52
- saneName := utils .SanitizeName (indexLibrary .Library .Name )
53
-
54
52
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 {
56
55
for _ , installedLib := range installedLibs {
57
56
if installedLib .Location != installLocation {
58
57
continue
@@ -72,7 +71,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
72
71
return nil , nil , fmt .Errorf (tr ("Builtin libraries directory not set" ))
73
72
}
74
73
75
- libPath := libsDir .Join (saneName )
74
+ libPath := libsDir .Join (utils . SanitizeName ( indexLibrary . Library . Name ) )
76
75
if replaced != nil && replaced .InstallDir .EquivalentTo (libPath ) {
77
76
78
77
} else if libPath .IsDir () {
@@ -99,9 +98,9 @@ func (lm *LibrariesManager) Uninstall(lib *libraries.Library) error {
99
98
return fmt .Errorf (tr ("removing lib directory: %s" ), err )
100
99
}
101
100
102
- alternatives := lm .Libraries [lib .Name ]
101
+ alternatives := lm .Libraries [lib .RealName ]
103
102
alternatives .Remove (lib )
104
- lm .Libraries [lib .Name ] = alternatives
103
+ lm .Libraries [lib .RealName ] = alternatives
105
104
return nil
106
105
}
107
106
@@ -191,8 +190,8 @@ func (lm *LibrariesManager) InstallZipLib(ctx context.Context, archivePath strin
191
190
192
191
// InstallGitLib installs a library hosted on a git repository on the specified path.
193
192
func (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 {
196
195
return fmt .Errorf (tr ("User directory not set" ))
197
196
}
198
197
@@ -204,10 +203,9 @@ func (lm *LibrariesManager) InstallGitLib(gitURL string, overwrite bool) error {
204
203
return err
205
204
}
206
205
207
- installPath := libsDir .Join (libraryName )
208
-
209
206
// Deletes libraries folder if already installed
210
- if _ , ok := lm .Libraries [libraryName ]; ok {
207
+ installPath := installDir .Join (libraryName )
208
+ if installPath .IsDir () {
211
209
if ! overwrite {
212
210
return fmt .Errorf (tr ("library %s already installed" ), libraryName )
213
211
}
@@ -217,6 +215,9 @@ func (lm *LibrariesManager) InstallGitLib(gitURL string, overwrite bool) error {
217
215
Trace ("Deleting library" )
218
216
installPath .RemoveAll ()
219
217
}
218
+ if installPath .Exist () {
219
+ return fmt .Errorf (tr ("could not create directory %s: a file with the same name exists!" , installPath ))
220
+ }
220
221
221
222
logrus .
222
223
WithField ("library name" , libraryName ).
0 commit comments