@@ -240,9 +240,6 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
240
240
})
241
241
}
242
242
243
- // Perform first-update of indexes if needed
244
- firstUpdate (context .Background (), req .GetInstance (), downloadCallback )
245
-
246
243
// Try to extract profile if specified
247
244
var profile * sketch.Profile
248
245
if req .GetProfile () != "" {
@@ -265,20 +262,11 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
265
262
})
266
263
}
267
264
268
- {
269
- // We need to rebuild the PackageManager currently in use by this instance
270
- // in case this is not the first Init on this instances, that might happen
271
- // after reinitializing an instance after installing or uninstalling a core.
272
- // If this is not done the information of the uninstall core is kept in memory,
273
- // even if it should not.
274
- pmb , commitPackageManager := instance .pm .NewBuilder ()
275
-
276
- // Load packages index
277
- urls := []string {globals .DefaultIndexURL }
278
- if profile == nil {
279
- urls = append (urls , configuration .Settings .GetStringSlice ("board_manager.additional_urls" )... )
280
- }
281
- for _ , u := range urls {
265
+ // Perform first-update of indexes if needed
266
+ defaultIndexURL , _ := utils .URLParse (globals .DefaultIndexURL )
267
+ allPackageIndexUrls := []* url.URL {defaultIndexURL }
268
+ if profile == nil {
269
+ for _ , u := range configuration .Settings .GetStringSlice ("board_manager.additional_urls" ) {
282
270
URL , err := utils .URLParse (u )
283
271
if err != nil {
284
272
e := & arduino.InitFailedError {
@@ -289,7 +277,21 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
289
277
responseError (e .ToRPCStatus ())
290
278
continue
291
279
}
280
+ allPackageIndexUrls = append (allPackageIndexUrls , URL )
281
+ }
282
+ }
283
+ firstUpdate (context .Background (), req .GetInstance (), downloadCallback , allPackageIndexUrls )
292
284
285
+ {
286
+ // We need to rebuild the PackageManager currently in use by this instance
287
+ // in case this is not the first Init on this instances, that might happen
288
+ // after reinitializing an instance after installing or uninstalling a core.
289
+ // If this is not done the information of the uninstall core is kept in memory,
290
+ // even if it should not.
291
+ pmb , commitPackageManager := instance .pm .NewBuilder ()
292
+
293
+ // Load packages index
294
+ for _ , URL := range allPackageIndexUrls {
293
295
if URL .Scheme == "file" {
294
296
_ , err := pmb .LoadPackageIndexFromFile (paths .New (URL .Path ))
295
297
if err != nil {
@@ -601,11 +603,10 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
601
603
602
604
// firstUpdate downloads libraries and packages indexes if they don't exist.
603
605
// This ideally is only executed the first time the CLI is run.
604
- func firstUpdate (ctx context.Context , instance * rpc.Instance , downloadCb func (msg * rpc.DownloadProgress )) error {
606
+ func firstUpdate (ctx context.Context , instance * rpc.Instance , downloadCb func (msg * rpc.DownloadProgress ), externalPackageIndexes [] * url. URL ) error {
605
607
// Gets the data directory to verify if library_index.json and package_index.json exist
606
608
dataDir := configuration .DataDir (configuration .Settings )
607
609
libraryIndex := dataDir .Join ("library_index.json" )
608
- packageIndex := dataDir .Join ("package_index.json" )
609
610
610
611
if libraryIndex .NotExist () {
611
612
// The library_index.json file doesn't exists, that means the CLI is run for the first time
@@ -616,13 +617,22 @@ func firstUpdate(ctx context.Context, instance *rpc.Instance, downloadCb func(ms
616
617
}
617
618
}
618
619
619
- if packageIndex .NotExist () {
620
- // The package_index.json file doesn't exists, that means the CLI is run for the first time,
621
- // similarly to the library update we download that file and all the other package indexes
622
- // from additional_urls
623
- req := & rpc.UpdateIndexRequest {Instance : instance , IgnoreCustomPackageIndexes : true }
624
- if err := UpdateIndex (ctx , req , downloadCb ); err != nil {
625
- return err
620
+ for _ , URL := range externalPackageIndexes {
621
+ if URL .Scheme == "file" {
622
+ continue
623
+ }
624
+ packageIndexFileName := (& resources.IndexResource {URL : URL }).IndexFileName ()
625
+ packageIndexFile := dataDir .Join (packageIndexFileName )
626
+ if packageIndexFile .NotExist () {
627
+ // The index file doesn't exists, that means the CLI is run for the first time,
628
+ // or the 3rd party package index URL has just been added. Similarly to the
629
+ // library update we download that file and all the other package indexes from
630
+ // additional_urls
631
+ req := & rpc.UpdateIndexRequest {Instance : instance }
632
+ if err := UpdateIndex (ctx , req , downloadCb ); err != nil {
633
+ return err
634
+ }
635
+ break
626
636
}
627
637
}
628
638
0 commit comments