@@ -19,7 +19,7 @@ import (
19
19
"context"
20
20
"fmt"
21
21
"net/url"
22
- "os "
22
+ "path/filepath "
23
23
"strings"
24
24
"sync"
25
25
@@ -490,7 +490,7 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequ
490
490
}
491
491
492
492
// UpdateIndex FIXMEDOC
493
- func UpdateIndex (ctx context.Context , req * rpc.UpdateIndexRequest , downloadCB rpc.DownloadProgressCB , downloadResultCB rpc. DownloadResultCB ) error {
493
+ func UpdateIndex (ctx context.Context , req * rpc.UpdateIndexRequest , downloadCB rpc.DownloadProgressCB ) error {
494
494
if instances .GetInstance (req .GetInstance ().GetId ()) == nil {
495
495
return & arduino.InvalidInstanceError {}
496
496
}
@@ -504,64 +504,39 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
504
504
505
505
failed := false
506
506
for _ , u := range urls {
507
- logrus .Info ("URL: " , u )
508
507
URL , err := utils .URLParse (u )
509
508
if err != nil {
510
509
logrus .Warnf ("unable to parse additional URL: %s" , u )
511
- downloadResultCB (& rpc.DownloadResult {
512
- Url : u ,
513
- Error : fmt .Sprintf ("%s: %v" , tr ("Unable to parse URL" ), err ),
514
- })
510
+ msg := fmt .Sprintf ("%s: %v" , tr ("Unable to parse URL" ), err )
511
+ downloadCB .Start (u , tr ("Downloading index: %s" , u ))
512
+ downloadCB .End (false , msg )
515
513
failed = true
516
514
continue
517
515
}
518
516
519
517
logrus .WithField ("url" , URL ).Print ("Updating index" )
520
518
521
519
if URL .Scheme == "file" {
520
+ downloadCB .Start (u , tr ("Downloading index: %s" , filepath .Base (URL .Path )))
522
521
path := paths .New (URL .Path )
523
522
if _ , err := packageindex .LoadIndexNoSign (path ); err != nil {
524
- downloadResultCB (& rpc.DownloadResult {
525
- Url : u ,
526
- Error : fmt .Sprintf ("%s: %v" , tr ("Invalid package index in %s" , path ), err ),
527
- })
523
+ msg := fmt .Sprintf ("%s: %v" , tr ("Invalid package index in %s" , path ), err )
524
+ downloadCB .End (false , msg )
528
525
failed = true
529
- continue
526
+ } else {
527
+ downloadCB .End (true , "" )
530
528
}
531
-
532
- fi , _ := os .Stat (path .String ())
533
- downloadCB (& rpc.DownloadProgress {
534
- File : tr ("Downloading index: %s" , path .Base ()),
535
- TotalSize : fi .Size (),
536
- })
537
- downloadCB (& rpc.DownloadProgress {Completed : true })
538
- downloadResultCB (& rpc.DownloadResult {
539
- Url : u ,
540
- Successful : true ,
541
- })
542
529
continue
543
530
}
544
531
545
- indexResource := resources.IndexResource {
546
- URL : URL ,
547
- }
532
+ indexResource := resources.IndexResource {URL : URL }
548
533
if strings .HasSuffix (URL .Host , "arduino.cc" ) && strings .HasSuffix (URL .Path , ".json" ) {
549
534
indexResource .SignatureURL , _ = url .Parse (u ) // should not fail because we already parsed it
550
535
indexResource .SignatureURL .Path += ".sig"
551
536
}
552
537
if err := indexResource .Download (indexpath , downloadCB ); err != nil {
553
- downloadResultCB (& rpc.DownloadResult {
554
- Url : u ,
555
- Error : err .Error (),
556
- })
557
538
failed = true
558
- continue
559
539
}
560
-
561
- downloadResultCB (& rpc.DownloadResult {
562
- Url : u ,
563
- Successful : true ,
564
- })
565
540
}
566
541
567
542
if failed {
@@ -571,17 +546,13 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
571
546
}
572
547
573
548
// UpdateCoreLibrariesIndex updates both Cores and Libraries indexes
574
- func UpdateCoreLibrariesIndex (ctx context.Context , req * rpc.UpdateCoreLibrariesIndexRequest , downloadCB rpc.DownloadProgressCB , downloadResultCB rpc.DownloadResultCB ) error {
575
- err := UpdateIndex (ctx , & rpc.UpdateIndexRequest {
576
- Instance : req .Instance ,
577
- }, downloadCB , downloadResultCB )
549
+ func UpdateCoreLibrariesIndex (ctx context.Context , req * rpc.UpdateCoreLibrariesIndexRequest , downloadCB rpc.DownloadProgressCB ) error {
550
+ err := UpdateIndex (ctx , & rpc.UpdateIndexRequest {Instance : req .Instance }, downloadCB )
578
551
if err != nil {
579
552
return err
580
553
}
581
554
582
- err = UpdateLibrariesIndex (ctx , & rpc.UpdateLibrariesIndexRequest {
583
- Instance : req .Instance ,
584
- }, downloadCB )
555
+ err = UpdateLibrariesIndex (ctx , & rpc.UpdateLibrariesIndexRequest {Instance : req .Instance }, downloadCB )
585
556
if err != nil {
586
557
return err
587
558
}
0 commit comments