@@ -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,6 +262,26 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
265
262
})
266
263
}
267
264
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" ) {
270
+ URL , err := utils .URLParse (u )
271
+ if err != nil {
272
+ e := & arduino.InitFailedError {
273
+ Code : codes .InvalidArgument ,
274
+ Cause : fmt .Errorf (tr ("Invalid additional URL: %v" , err )),
275
+ Reason : rpc .FailedInstanceInitReason_FAILED_INSTANCE_INIT_REASON_INVALID_INDEX_URL ,
276
+ }
277
+ responseError (e .ToRPCStatus ())
278
+ continue
279
+ }
280
+ allPackageIndexUrls = append (allPackageIndexUrls , URL )
281
+ }
282
+ }
283
+ firstUpdate (context .Background (), req .GetInstance (), downloadCallback , allPackageIndexUrls )
284
+
268
285
{
269
286
// We need to rebuild the PackageManager currently in use by this instance
270
287
// in case this is not the first Init on this instances, that might happen
@@ -299,22 +316,7 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
299
316
}
300
317
301
318
// Load packages index
302
- urls := []string {globals .DefaultIndexURL }
303
- if profile == nil {
304
- urls = append (urls , configuration .Settings .GetStringSlice ("board_manager.additional_urls" )... )
305
- }
306
- for _ , u := range urls {
307
- URL , err := utils .URLParse (u )
308
- if err != nil {
309
- e := & arduino.InitFailedError {
310
- Code : codes .InvalidArgument ,
311
- Cause : fmt .Errorf (tr ("Invalid additional URL: %v" , err )),
312
- Reason : rpc .FailedInstanceInitReason_FAILED_INSTANCE_INIT_REASON_INVALID_INDEX_URL ,
313
- }
314
- responseError (e .ToRPCStatus ())
315
- continue
316
- }
317
-
319
+ for _ , URL := range allPackageIndexUrls {
318
320
if URL .Scheme == "file" {
319
321
_ , err := pmb .LoadPackageIndexFromFile (paths .New (URL .Path ))
320
322
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