@@ -20,7 +20,9 @@ import (
2020
2121 "github.com/arduino/arduino-cli/cli/output"
2222 "github.com/arduino/arduino-cli/commands"
23+ "github.com/arduino/arduino-cli/configuration"
2324 rpc "github.com/arduino/arduino-cli/rpc/commands"
25+ "github.com/arduino/go-paths-helper"
2426 "github.com/pkg/errors"
2527 "github.com/sirupsen/logrus"
2628)
@@ -51,9 +53,13 @@ func getInitResponse() (*rpc.InitResp, error) {
5153 return nil , errors .Wrap (err , "creating instance" )
5254 }
5355
54- // Init() succeeded but there were errors loading library indexes,
55- // let's rescan and try again
56- if resp .GetLibrariesIndexError () != "" {
56+ // Gets the data directory to verify if library_index.json and package_index.json exist
57+ dataDir := paths .New (configuration .Settings .GetString ("directories.data" ))
58+
59+ // The library_index.json file doesn't exists, that means the CLI is run for the first time
60+ // so we proceed with the first update that downloads the file
61+ libraryIndex := dataDir .Join ("library_index.json" )
62+ if libraryIndex .NotExist () {
5763 logrus .Warnf ("There were errors loading the library index, trying again..." )
5864
5965 // update all indexes
@@ -80,15 +86,11 @@ func getInitResponse() (*rpc.InitResp, error) {
8086 resp .PlatformsIndexErrors = rescanResp .PlatformsIndexErrors
8187 }
8288
83- // Init() succeeded but there were errors loading platform indexes,
84- // let's rescan and try again
85- if resp .GetPlatformsIndexErrors () != nil {
86-
87- // log each error
88- for _ , err := range resp .GetPlatformsIndexErrors () {
89- logrus .Errorf ("Error loading platform index: %v" , err )
90- }
91-
89+ // The package_index.json file doesn't exists, that means the CLI is run for the first time,
90+ // similarly to the library update we download that file and all the other package indexes
91+ // from additional_urls
92+ packageIndex := dataDir .Join ("package_index.json" )
93+ if packageIndex .NotExist () {
9294 // update platform index
9395 _ , err := commands .UpdateIndex (context .Background (),
9496 & rpc.UpdateIndexReq {Instance : resp .GetInstance ()}, output .ProgressBar ())
0 commit comments