Skip to content

Commit

Permalink
librariesindex: Fix nil pointer. Refs #1176
Browse files Browse the repository at this point in the history
Let the library index return the latest known version,
if a library without a version is found.

Signed-off-by: Ruben Jenster <[email protected]>
  • Loading branch information
r10r authored and silvanocerza committed Feb 18, 2021
1 parent 2c7b6ba commit 8a5cddc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arduino/libraries/librariesindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package librariesindex

import (
"fmt"
"sort"

"github.com/arduino/arduino-cli/arduino/libraries"
Expand Down Expand Up @@ -136,6 +137,10 @@ func (idx *Index) FindLibraryUpdate(lib *libraries.Library) *Release {
if indexLib == nil {
return nil
}
if lib.Version == nil {
fmt.Printf("[WARN] version for library loaded from %s is nil\n", lib.InstallDir)
return indexLib.Latest
}
if indexLib.Latest.Version.GreaterThan(lib.Version) {
return indexLib.Latest
}
Expand Down
4 changes: 4 additions & 0 deletions arduino/libraries/librariesindex/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func TestIndexer(t *testing.T) {
require.NotNil(t, rtcUpdate)
require.Equal(t, "[email protected]", rtcUpdate.String())

rtcUpdateNoVersion := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: nil})
require.NotNil(t, rtcUpdateNoVersion)
require.Equal(t, "[email protected]", rtcUpdateNoVersion.String())

rtcNoUpdate := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: semver.MustParse("3.0.0")})
require.Nil(t, rtcNoUpdate)

Expand Down

0 comments on commit 8a5cddc

Please sign in to comment.