Skip to content

Commit efa9532

Browse files
committed
Refactored some librarymanager functions to query libraries list
1 parent 3b1449f commit efa9532

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

Diff for: arduino/libraries/librariesmanager/librariesmanager.go

+7-20
Original file line numberDiff line numberDiff line change
@@ -205,26 +205,13 @@ func (lm *LibrariesManager) LoadLibraryFromDir(libRootDir *paths.Path, location
205205
return nil
206206
}
207207

208-
// FindByReference return the installed library matching the Reference
209-
// name and version or, if the version is nil, the library installed
210-
// in the User folder.
211-
func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, installLocation libraries.LibraryLocation) *libraries.Library {
212-
alternatives, have := lm.Libraries[libRef.Name]
213-
if !have {
208+
// FindByReference return the installed libraries matching the Reference
209+
// name and version or, if the version is nil, the libraries installed
210+
// in the installLocation.
211+
func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, installLocation libraries.LibraryLocation) libraries.List {
212+
alternatives := lm.Libraries[libRef.Name]
213+
if alternatives == nil {
214214
return nil
215215
}
216-
// TODO: Move "search into user" into another method...
217-
if libRef.Version == nil {
218-
for _, candidate := range alternatives {
219-
if candidate.Location == installLocation {
220-
return candidate
221-
}
222-
}
223-
return nil
224-
}
225-
res := alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation)
226-
if len(res) > 0 {
227-
return res[0]
228-
}
229-
return nil
216+
return alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation)
230217
}

Diff for: commands/lib/uninstall.go

+4-4
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)