Skip to content

Commit 735b317

Browse files
add new props to Index and Platform to understand if the platform is globally indexed
1 parent e7a8321 commit 735b317

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

arduino/cores/cores.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Platform struct {
4444
Package *Package `json:"-"`
4545
ManuallyInstalled bool // true if the Platform has been installed without the CLI
4646
Deprecated bool // true if the Platform has been deprecated
47+
Indexed bool // true if the Platform has been indexed from additional-urls
4748
}
4849

4950
// PlatformReleaseHelp represents the help URL for this Platform release
@@ -409,3 +410,16 @@ func (release *PlatformRelease) MarshalJSON() ([]byte, error) {
409410
Name: release.Platform.Name,
410411
})
411412
}
413+
414+
// HasMetadata returns true if the PlatformRelease installation dir contains the installed.json file
415+
func (release *PlatformRelease) HasMetadata() bool {
416+
if release.InstallDir == nil {
417+
return false
418+
}
419+
420+
installedJSONPath := release.InstallDir.Join("installed.json")
421+
if installedJSONPath == nil {
422+
return false
423+
}
424+
return installedJSONPath.Exist()
425+
}

arduino/cores/packageindex/index.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ import (
3333
//
3434
//easyjson:json
3535
type Index struct {
36-
Packages []*indexPackage `json:"packages"`
37-
IsTrusted bool
36+
Packages []*indexPackage `json:"packages"`
37+
IsTrusted bool
38+
isInstalledJSON bool
3839
}
3940

4041
// indexPackage represents a single entry from package_index.json file.
@@ -144,7 +145,7 @@ var tr = i18n.Tr
144145
// with the existing contents of the cores.Packages passed as parameter.
145146
func (index Index) MergeIntoPackages(outPackages cores.Packages) {
146147
for _, inPackage := range index.Packages {
147-
inPackage.extractPackageIn(outPackages, index.IsTrusted)
148+
inPackage.extractPackageIn(outPackages, index.IsTrusted, index.isInstalledJSON)
148149
}
149150
}
150151

@@ -243,7 +244,7 @@ func IndexFromPlatformRelease(pr *cores.PlatformRelease) Index {
243244
}
244245
}
245246

246-
func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages, trusted bool) {
247+
func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages, trusted bool, isInstallJSON bool) {
247248
outPackage := outPackages.GetOrCreatePackage(inPackage.Name)
248249
outPackage.Maintainer = inPackage.Maintainer
249250
outPackage.WebsiteURL = inPackage.WebsiteURL
@@ -256,15 +257,19 @@ func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages, trust
256257
}
257258

258259
for _, inPlatform := range inPackage.Platforms {
259-
inPlatform.extractPlatformIn(outPackage, trusted)
260+
inPlatform.extractPlatformIn(outPackage, trusted, isInstallJSON)
260261
}
261262
}
262263

263-
func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *cores.Package, trusted bool) error {
264+
func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *cores.Package, trusted bool, isInstallJSON bool) error {
264265
outPlatform := outPackage.GetOrCreatePlatform(inPlatformRelease.Architecture)
265266
// FIXME: shall we use the Name and Category of the latest release? or maybe move Name and Category in PlatformRelease?
266267
outPlatform.Name = inPlatformRelease.Name
267268
outPlatform.Category = inPlatformRelease.Category
269+
// If the variable `isInstallJSON` is false it means that the index we're reading is coming from the additional-urls.
270+
// Therefore, the `outPlatform.Indexed` will be set at `true`.
271+
outPlatform.Indexed = outPlatform.Indexed || !isInstallJSON
272+
268273
// If the Platform is installed before deprecation installed.json file does not include "deprecated" field.
269274
// The installed.json is read during loading phase of an installed Platform, if the deprecated field is not found
270275
// the package_index.json field would be overwritten and the deprecation info would be lost.
@@ -398,6 +403,11 @@ func LoadIndex(jsonIndexFile *paths.Path) (*Index, error) {
398403
} else {
399404
logrus.WithField("index", jsonIndexFile).Infof("Missing signature file")
400405
}
406+
407+
if jsonIndexFile.Base() == "installed.json" {
408+
index.isInstalledJSON = true
409+
}
410+
401411
return &index, nil
402412
}
403413

0 commit comments

Comments
 (0)