@@ -28,6 +28,7 @@ import (
28
28
"github.com/arduino/go-paths-helper"
29
29
"github.com/sirupsen/logrus"
30
30
semver "go.bug.st/relaxed-semver"
31
+ "golang.org/x/exp/slices"
31
32
)
32
33
33
34
// Index represents Boards struct as seen from module_firmware_index.json file.
@@ -128,7 +129,14 @@ func LoadIndexNoSign(jsonIndexFile *paths.Path) (*Index, error) {
128
129
// MergeWith merge this index with the other given index (the boards from the other index)
129
130
// are added to this one.
130
131
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
+ }
132
140
i .IsTrusted = i .IsTrusted && j .IsTrusted
133
141
}
134
142
@@ -142,6 +150,13 @@ func (i *Index) GetBoard(fqbn string) *IndexBoard {
142
150
return nil
143
151
}
144
152
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
+
145
160
// GetFirmware returns the specified IndexFirmware version for this board.
146
161
// Returns nil if version is not found.
147
162
func (b * IndexBoard ) GetFirmware (version string ) * IndexFirmware {
0 commit comments