The Wayback Machine - https://web.archive.org/web/20211120000341/https://github.com/arduino/arduino-cli/commit/f7b22f7653ba1094942cee5d67b322763ce00892
Skip to content
Permalink
Browse files
fix core list --all sometimes crashing (#1519)
* fix packages being added to the package manager even if they were not respecting the specification

* add test to check if if the bug it's fixed

* fix platform release being nil and causing panic with indexes not compliant with specs

* add test to check if the bug is fixed

* add comments and optimize the code a little bit

* Apply suggestions from code review

Co-authored-by: per1234 <[email protected]>

Co-authored-by: per1234 <[email protected]>
  • Loading branch information
umbynos and per1234 committed Oct 25, 2021
1 parent 8e6f93f commit f7b22f7653ba1094942cee5d67b322763ce00892
Showing with 265 additions and 240 deletions.
  1. +5 −1 arduino/cores/packagemanager/loader.go
  2. +12 −9 commands/core/list.go
  3. +230 −230 i18n/data/en.po
  4. +18 −0 test/test_core.py
@@ -145,6 +145,10 @@ func (pm *PackageManager) LoadHardwareFromDirectory(path *paths.Path) []*status.
statuses = append(statuses, errs...)
}
}
// If the Package does not contain Platforms or Tools we remove it since does not contain anything valuable
if len(targetPackage.Platforms) == 0 && len(targetPackage.Tools) == 0 {
delete(pm.Packages, packager)
}
}

return statuses
@@ -262,7 +266,6 @@ func (pm *PackageManager) loadPlatform(targetPackage *cores.Package, platformPat
// case: ARCHITECTURE/VERSION/boards.txt
// let's dive into VERSION directories

platform := targetPackage.GetOrCreatePlatform(architecture)
versionDirs, err := platformPath.ReadDir()
if err != nil {
return status.Newf(codes.FailedPrecondition, tr("reading dir %[1]s: %[2]s"), platformPath, err)
@@ -280,6 +283,7 @@ func (pm *PackageManager) loadPlatform(targetPackage *cores.Package, platformPat
if err != nil {
return status.Newf(codes.FailedPrecondition, tr("invalid version dir %[1]s: %[2]s"), versionDir, err)
}
platform := targetPackage.GetOrCreatePlatform(architecture)
release := platform.GetOrCreateRelease(version)
if err := pm.loadPlatformRelease(release, versionDir); err != nil {
return status.Newf(codes.FailedPrecondition, tr("loading platform release %[1]s: %[2]s"), release, err)
@@ -38,18 +38,22 @@ func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) {
for _, platform := range targetPackage.Platforms {
platformRelease := packageManager.GetInstalledPlatformRelease(platform)

// The All flags adds to the list of installed platforms the installable platforms (from the indexes)
// If both All and UpdatableOnly are set All takes precedence
if req.All {
installedVersion := ""
if platformRelease == nil {
if platformRelease == nil { // if the platform is not installed
platformRelease = platform.GetLatestRelease()
} else {
installedVersion = platformRelease.Version.String()
}
rpcPlatform := commands.PlatformReleaseToRPC(platform.GetLatestRelease())
rpcPlatform.Installed = installedVersion
res = append(res, rpcPlatform)
continue
// it could happen, especially with indexes not perfectly compliant with specs that a platform do not contain a valid release
if platformRelease != nil {
rpcPlatform := commands.PlatformReleaseToRPC(platformRelease)
rpcPlatform.Installed = installedVersion
res = append(res, rpcPlatform)
continue
}
}

if platformRelease != nil {
@@ -58,10 +62,9 @@ func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) {
return nil, &arduino.PlatformNotFoundError{Platform: platform.String(), Cause: fmt.Errorf(tr("the platform has no releases"))}
}

if req.UpdatableOnly {
if latest == platformRelease {
continue
}
// show only the updatable platforms
if req.UpdatableOnly && latest == platformRelease {
continue
}

rpcPlatform := commands.PlatformReleaseToRPC(platformRelease)
Loading

0 comments on commit f7b22f7

Please sign in to comment.