@@ -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.
130131func (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.
147162func (b * IndexBoard ) GetFirmware (version string ) * IndexFirmware {
0 commit comments