Skip to content

Commit 5ececd3

Browse files
committed
Refactored some librarymanager functions to query libraries list
1 parent 04cb693 commit 5ececd3

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

arduino/libraries/librariesmanager/librariesmanager.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -199,26 +199,13 @@ func (lm *LibrariesManager) LoadLibraryFromDir(libRootDir *paths.Path, location
199199
return nil
200200
}
201201

202-
// FindByReference return the installed library matching the Reference
203-
// name and version or, if the version is nil, the library installed
204-
// in the User folder.
205-
func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, installLocation libraries.LibraryLocation) *libraries.Library {
206-
alternatives, have := lm.Libraries[libRef.Name]
207-
if !have {
202+
// FindByReference return the installed libraries matching the Reference
203+
// name and version or, if the version is nil, the libraries installed
204+
// in the installLocation.
205+
func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, installLocation libraries.LibraryLocation) libraries.List {
206+
alternatives := lm.Libraries[libRef.Name]
207+
if alternatives == nil {
208208
return nil
209209
}
210-
// TODO: Move "search into user" into another method...
211-
if libRef.Version == nil {
212-
for _, candidate := range alternatives {
213-
if candidate.Location == installLocation {
214-
return candidate
215-
}
216-
}
217-
return nil
218-
}
219-
res := alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation)
220-
if len(res) > 0 {
221-
return res[0]
222-
}
223-
return nil
210+
return alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation)
224211
}

commands/lib/uninstall.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallRequest, tas
3232
return &arduino.InvalidLibraryError{Cause: err}
3333
}
3434

35-
lib := lm.FindByReference(ref, libraries.User)
35+
libs := lm.FindByReference(ref, libraries.User)
3636

37-
if lib == nil {
37+
if len(libs) == 0 {
3838
taskCB(&rpc.TaskProgress{Message: tr("Library %s is not installed", req.Name), Completed: true})
3939
} else {
40-
taskCB(&rpc.TaskProgress{Name: tr("Uninstalling %s", lib)})
41-
lm.Uninstall(lib)
40+
taskCB(&rpc.TaskProgress{Name: tr("Uninstalling %s", libs[0])})
41+
lm.Uninstall(libs[0])
4242
taskCB(&rpc.TaskProgress{Completed: true})
4343
}
4444

0 commit comments

Comments
 (0)