Skip to content

Commit d32d6c0

Browse files
committed
Fixed progress bar in library index download
1 parent 0460549 commit d32d6c0

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

cli/cli.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/arduino/arduino-cli/commands"
3232
"github.com/arduino/arduino-cli/common/formatter"
3333
"github.com/arduino/arduino-cli/configs"
34+
"github.com/arduino/arduino-cli/output"
3435
"github.com/arduino/arduino-cli/rpc"
3536
paths "github.com/arduino/go-paths-helper"
3637
"github.com/sirupsen/logrus"
@@ -119,6 +120,20 @@ func InitInstance(libManagerOnly bool) *rpc.InitResp {
119120
}
120121
os.Exit(ErrGeneric)
121122
}
123+
if resp.GetLibrariesIndexError() != "" {
124+
commands.UpdateLibrariesIndex(context.Background(), commands.GetLibraryManager(resp), output.DownloadProgressBar())
125+
rescResp, err := commands.Rescan(context.Background(), &rpc.RescanReq{Instance: resp.GetInstance()})
126+
if rescResp.GetLibrariesIndexError() != "" {
127+
formatter.PrintErrorMessage("Error loading library index: " + rescResp.GetLibrariesIndexError())
128+
os.Exit(ErrGeneric)
129+
}
130+
if err != nil {
131+
formatter.PrintError(err, "Error loading library index")
132+
os.Exit(ErrGeneric)
133+
}
134+
resp.LibrariesIndexError = rescResp.LibrariesIndexError
135+
resp.PlatformsIndexErrors = rescResp.PlatformsIndexErrors
136+
}
122137
return resp
123138
}
124139

commands/instances.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,28 +126,17 @@ func Destroy(ctx context.Context, req *rpc.DestroyReq) (*rpc.DestroyResp, error)
126126
}
127127

128128
// UpdateLibrariesIndex updates the library_index.json
129-
func UpdateLibrariesIndex(ctx context.Context, lm *librariesmanager.LibrariesManager, progressCallback func(*rpc.DownloadProgress)) {
129+
func UpdateLibrariesIndex(ctx context.Context, lm *librariesmanager.LibrariesManager, downloadCB func(*rpc.DownloadProgress)) error {
130130
logrus.Info("Updating libraries index")
131131
d, err := lm.UpdateIndex()
132132
if err != nil {
133-
//formatter.PrintError(err, "Error downloading librarires index")
134-
//os.Exit(ErrNetwork)
133+
return err
135134
}
136-
//formatter.DownloadProgressBar(d, "Updating index: library_index.json")
137-
//d.Run()
138-
progressCallback(&rpc.DownloadProgress{
139-
File: "library_index.json",
140-
Url: d.URL,
141-
TotalSize: d.Size(),
142-
})
143-
d.RunAndPoll(func(downloaded int64) {
144-
progressCallback(&rpc.DownloadProgress{Downloaded: downloaded})
145-
}, 250*time.Millisecond)
146-
135+
Download(d, "library_index.json", downloadCB)
147136
if d.Error() != nil {
148-
//formatter.PrintError(d.Error(), "Error downloading librarires index")
149-
//os.Exit(ErrNetwork)
137+
return d.Error()
150138
}
139+
return nil
151140
}
152141

153142
func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB DownloadProgressCB) (*rpc.UpdateIndexResp, error) {

0 commit comments

Comments
 (0)