@@ -20,7 +20,9 @@ import (
20
20
21
21
"github.com/arduino/arduino-cli/cli/output"
22
22
"github.com/arduino/arduino-cli/commands"
23
+ "github.com/arduino/arduino-cli/configuration"
23
24
rpc "github.com/arduino/arduino-cli/rpc/commands"
25
+ "github.com/arduino/go-paths-helper"
24
26
"github.com/pkg/errors"
25
27
"github.com/sirupsen/logrus"
26
28
)
@@ -51,9 +53,13 @@ func getInitResponse() (*rpc.InitResp, error) {
51
53
return nil , errors .Wrap (err , "creating instance" )
52
54
}
53
55
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 () {
57
63
logrus .Warnf ("There were errors loading the library index, trying again..." )
58
64
59
65
// update all indexes
@@ -80,15 +86,11 @@ func getInitResponse() (*rpc.InitResp, error) {
80
86
resp .PlatformsIndexErrors = rescanResp .PlatformsIndexErrors
81
87
}
82
88
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 () {
92
94
// update platform index
93
95
_ , err := commands .UpdateIndex (context .Background (),
94
96
& rpc.UpdateIndexReq {Instance : resp .GetInstance ()}, output .ProgressBar ())
0 commit comments