@@ -19,7 +19,6 @@ import (
1919 "context"
2020 "fmt"
2121 "net/url"
22- "os"
2322 "strings"
2423 "sync"
2524
@@ -490,7 +489,7 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequ
490489}
491490
492491// UpdateIndex FIXMEDOC
493- func UpdateIndex (ctx context.Context , req * rpc.UpdateIndexRequest , downloadCB rpc.DownloadProgressCB , downloadResultCB rpc. DownloadResultCB ) error {
492+ func UpdateIndex (ctx context.Context , req * rpc.UpdateIndexRequest , downloadCB rpc.DownloadProgressCB ) error {
494493 if instances .GetInstance (req .GetInstance ().GetId ()) == nil {
495494 return & arduino.InvalidInstanceError {}
496495 }
@@ -504,14 +503,12 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
504503
505504 failed := false
506505 for _ , u := range urls {
507- logrus . Info ( "URL: " , u )
506+ downloadCB ( rpc . NewDownloadProgressStart ( u , tr ( "Downloading index: %s " , 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 (rpc .NewDownloadProgressEnd (false , msg ))
515512 failed = true
516513 continue
517514 }
@@ -521,47 +518,27 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
521518 if URL .Scheme == "file" {
522519 path := paths .New (URL .Path )
523520 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- })
521+ msg := fmt .Sprintf ("%s: %v" , tr ("Invalid package index in %s" , path ), err )
522+ downloadCB (rpc .NewDownloadProgressEnd (false , msg ))
528523 failed = true
529- continue
524+ } else {
525+ downloadCB (rpc .NewDownloadProgressEnd (true , "" ))
530526 }
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- })
542527 continue
543528 }
544529
545- indexResource := resources.IndexResource {
546- URL : URL ,
547- }
530+ indexResource := resources.IndexResource {URL : URL }
548531 if strings .HasSuffix (URL .Host , "arduino.cc" ) && strings .HasSuffix (URL .Path , ".json" ) {
549532 indexResource .SignatureURL , _ = url .Parse (u ) // should not fail because we already parsed it
550533 indexResource .SignatureURL .Path += ".sig"
551534 }
552535 if err := indexResource .Download (indexpath , downloadCB ); err != nil {
553- downloadResultCB (& rpc.DownloadResult {
554- Url : u ,
555- Error : err .Error (),
556- })
536+ downloadCB (rpc .NewDownloadProgressEnd (false , err .Error ()))
557537 failed = true
558- continue
538+ } else {
539+ downloadCB (rpc .NewDownloadProgressEnd (true , "" ))
559540 }
560-
561- downloadResultCB (& rpc.DownloadResult {
562- Url : u ,
563- Successful : true ,
564- })
541+ continue
565542 }
566543
567544 if failed {
@@ -571,17 +548,13 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
571548}
572549
573550// 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 )
551+ func UpdateCoreLibrariesIndex (ctx context.Context , req * rpc.UpdateCoreLibrariesIndexRequest , downloadCB rpc.DownloadProgressCB ) error {
552+ err := UpdateIndex (ctx , & rpc.UpdateIndexRequest {Instance : req .Instance }, downloadCB )
578553 if err != nil {
579554 return err
580555 }
581556
582- err = UpdateLibrariesIndex (ctx , & rpc.UpdateLibrariesIndexRequest {
583- Instance : req .Instance ,
584- }, downloadCB )
557+ err = UpdateLibrariesIndex (ctx , & rpc.UpdateLibrariesIndexRequest {Instance : req .Instance }, downloadCB )
585558 if err != nil {
586559 return err
587560 }
0 commit comments