Skip to content

Commit 2dff44f

Browse files
committed
Allow merging with overwrite
This means that additional indexex are allowed to overwrite official boards.
1 parent 50a2387 commit 2dff44f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
go.bug.st/downloader/v2 v2.1.1
1515
go.bug.st/relaxed-semver v0.10.2
1616
go.bug.st/serial v1.3.2
17+
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
1718
gopkg.in/yaml.v3 v3.0.1
1819
)
1920

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
341341
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
342342
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
343343
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
344+
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
345+
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
344346
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
345347
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
346348
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=

Diff for: indexes/firmwareindex/firmwareindex.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/arduino/go-paths-helper"
2929
"github.com/sirupsen/logrus"
3030
semver "go.bug.st/relaxed-semver"
31+
"golang.org/x/exp/slices"
3132
)
3233

3334
// Index represents Boards struct as seen from module_firmware_index.json file.
@@ -128,7 +129,14 @@ func LoadIndexNoSign(jsonIndexFile *paths.Path) (*Index, error) {
128129
// MergeWith merge this index with the other given index (the boards from the other index)
129130
// are added to this one.
130131
func (i *Index) MergeWith(j *Index) {
131-
i.Boards = append(i.Boards, j.Boards...)
132+
for _, boardToAdd := range j.Boards {
133+
idx := slices.IndexFunc(i.Boards, func(x *IndexBoard) bool { return x.Overlaps(boardToAdd) })
134+
if idx == -1 {
135+
i.Boards = append(i.Boards, boardToAdd)
136+
} else {
137+
i.Boards[idx] = boardToAdd
138+
}
139+
}
132140
i.IsTrusted = i.IsTrusted && j.IsTrusted
133141
}
134142

@@ -142,6 +150,13 @@ func (i *Index) GetBoard(fqbn string) *IndexBoard {
142150
return nil
143151
}
144152

153+
// Overlaps returns true if the two IndexBoard represent the same board.
154+
func (b *IndexBoard) Overlaps(x *IndexBoard) bool {
155+
return b.Fqbn == x.Fqbn &&
156+
b.Module == x.Module &&
157+
b.Name == x.Name
158+
}
159+
145160
// GetFirmware returns the specified IndexFirmware version for this board.
146161
// Returns nil if version is not found.
147162
func (b *IndexBoard) GetFirmware(version string) *IndexFirmware {

0 commit comments

Comments
 (0)