@@ -19,7 +19,7 @@ import (
1919 "context"
2020 "fmt"
2121 "net/url"
22- "os "
22+ "path/filepath "
2323 "strings"
2424 "sync"
2525
@@ -490,7 +490,7 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequ
490490}
491491
492492// 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 {
494494 if instances .GetInstance (req .GetInstance ().GetId ()) == nil {
495495 return & arduino.InvalidInstanceError {}
496496 }
@@ -504,64 +504,39 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
504504
505505 failed := false
506506 for _ , u := range urls {
507- logrus .Info ("URL: " , u )
508507 URL , err := utils .URLParse (u )
509508 if err != nil {
510509 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 )
515513 failed = true
516514 continue
517515 }
518516
519517 logrus .WithField ("url" , URL ).Print ("Updating index" )
520518
521519 if URL .Scheme == "file" {
520+ downloadCB .Start (u , tr ("Downloading index: %s" , filepath .Base (URL .Path )))
522521 path := paths .New (URL .Path )
523522 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 )
528525 failed = true
529- continue
526+ } else {
527+ downloadCB .End (true , "" )
530528 }
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- })
542529 continue
543530 }
544531
545- indexResource := resources.IndexResource {
546- URL : URL ,
547- }
532+ indexResource := resources.IndexResource {URL : URL }
548533 if strings .HasSuffix (URL .Host , "arduino.cc" ) && strings .HasSuffix (URL .Path , ".json" ) {
549534 indexResource .SignatureURL , _ = url .Parse (u ) // should not fail because we already parsed it
550535 indexResource .SignatureURL .Path += ".sig"
551536 }
552537 if err := indexResource .Download (indexpath , downloadCB ); err != nil {
553- downloadResultCB (& rpc.DownloadResult {
554- Url : u ,
555- Error : err .Error (),
556- })
557538 failed = true
558- continue
559539 }
560- 561- downloadResultCB (& rpc.DownloadResult {
562- Url : u ,
563- Successful : true ,
564- })
565540 }
566541
567542 if failed {
@@ -571,17 +546,13 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
571546}
572547
573548// 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 )
578551 if err != nil {
579552 return err
580553 }
581554
582- err = UpdateLibrariesIndex (ctx , & rpc.UpdateLibrariesIndexRequest {
583- Instance : req .Instance ,
584- }, downloadCB )
555+ err = UpdateLibrariesIndex (ctx , & rpc.UpdateLibrariesIndexRequest {Instance : req .Instance }, downloadCB )
585556 if err != nil {
586557 return err
587558 }
0 commit comments