Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f7b22f7

Browse files
umbynosper1234
andauthored
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 <accounts@perglass.com> Co-authored-by: per1234 <accounts@perglass.com>
1 parent 8e6f93f commit f7b22f7

File tree

4 files changed

+265
-240
lines changed

4 files changed

+265
-240
lines changed

‎arduino/cores/packagemanager/loader.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ func (pm *PackageManager) LoadHardwareFromDirectory(path *paths.Path) []*status.
145145
statuses = append(statuses, errs...)
146146
}
147147
}
148+
// If the Package does not contain Platforms or Tools we remove it since does not contain anything valuable
149+
if len(targetPackage.Platforms) == 0 && len(targetPackage.Tools) == 0 {
150+
delete(pm.Packages, packager)
151+
}
148152
}
149153

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

265-
platform := targetPackage.GetOrCreatePlatform(architecture)
266269
versionDirs, err := platformPath.ReadDir()
267270
if err != nil {
268271
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
280283
if err != nil {
281284
return status.Newf(codes.FailedPrecondition, tr("invalid version dir %[1]s: %[2]s"), versionDir, err)
282285
}
286+
platform := targetPackage.GetOrCreatePlatform(architecture)
283287
release := platform.GetOrCreateRelease(version)
284288
if err := pm.loadPlatformRelease(release, versionDir); err != nil {
285289
return status.Newf(codes.FailedPrecondition, tr("loading platform release %[1]s: %[2]s"), release, err)

‎commands/core/list.go‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,22 @@ func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) {
3838
for _, platform := range targetPackage.Platforms {
3939
platformRelease := packageManager.GetInstalledPlatformRelease(platform)
4040

41+
// The All flags adds to the list of installed platforms the installable platforms (from the indexes)
4142
// If both All and UpdatableOnly are set All takes precedence
4243
if req.All {
4344
installedVersion := ""
44-
if platformRelease == nil {
45+
if platformRelease == nil {// if the platform is not installed
4546
platformRelease = platform.GetLatestRelease()
4647
} else {
4748
installedVersion = platformRelease.Version.String()
4849
}
49-
rpcPlatform := commands.PlatformReleaseToRPC(platform.GetLatestRelease())
50-
rpcPlatform.Installed = installedVersion
51-
res = append(res, rpcPlatform)
52-
continue
50+
// it could happen, especially with indexes not perfectly compliant with specs that a platform do not contain a valid release
51+
if platformRelease != nil {
52+
rpcPlatform := commands.PlatformReleaseToRPC(platformRelease)
53+
rpcPlatform.Installed = installedVersion
54+
res = append(res, rpcPlatform)
55+
continue
56+
}
5357
}
5458

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

61-
if req.UpdatableOnly {
62-
if latest == platformRelease {
63-
continue
64-
}
65+
// show only the updatable platforms
66+
if req.UpdatableOnly && latest == platformRelease {
67+
continue
6568
}
6669

6770
rpcPlatform := commands.PlatformReleaseToRPC(platformRelease)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /