@@ -32,6 +32,7 @@ import (
32
32
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
33
33
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
34
34
"github.com/arduino/arduino-cli/arduino/security"
35
+ "github.com/arduino/arduino-cli/arduino/utils"
35
36
"github.com/arduino/arduino-cli/cli/globals"
36
37
"github.com/arduino/arduino-cli/configuration"
37
38
rpc "github.com/arduino/arduino-cli/rpc/commands"
@@ -202,36 +203,33 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo
202
203
203
204
indexpath := paths .New (configuration .Settings .GetString ("directories.Data" ))
204
205
205
- for _ , x := range configuration .Settings .GetStringSlice ("board_manager.additional_paths" ) {
206
- logrus .Info ("JSON PATH: " , x )
207
-
208
- pathJSON , _ := paths .New (x ).Abs ()
209
-
210
- if _ , err := packageindex .LoadIndexNoSign (pathJSON ); err != nil {
211
- return nil , fmt .Errorf ("invalid package index in %s: %s" , pathJSON , err )
212
- }
213
-
214
- fi , _ := os .Stat (x )
215
- downloadCB (& rpc.DownloadProgress {
216
- File : "Updating index: " + pathJSON .Base (),
217
- TotalSize : fi .Size (),
218
- })
219
- downloadCB (& rpc.DownloadProgress {Completed : true })
220
-
221
- }
222
-
223
206
urls := []string {globals .DefaultIndexURL }
224
207
urls = append (urls , configuration .Settings .GetStringSlice ("board_manager.additional_urls" )... )
225
208
for _ , u := range urls {
226
209
logrus .Info ("URL: " , u )
227
- URL , err := url . Parse (u )
210
+ URL , err := utils . URLParse (u )
228
211
if err != nil {
229
212
logrus .Warnf ("unable to parse additional URL: %s" , u )
230
213
continue
231
214
}
232
215
233
216
logrus .WithField ("url" , URL ).Print ("Updating index" )
234
217
218
+ if URL .Scheme == "file" {
219
+ path := paths .New (URL .Path )
220
+ if _ , err := packageindex .LoadIndexNoSign (path ); err != nil {
221
+ return nil , fmt .Errorf ("invalid package index in %s: %s" , path , err )
222
+ }
223
+
224
+ fi , _ := os .Stat (path .String ())
225
+ downloadCB (& rpc.DownloadProgress {
226
+ File : "Updating index: " + path .Base (),
227
+ TotalSize : fi .Size (),
228
+ })
229
+ downloadCB (& rpc.DownloadProgress {Completed : true })
230
+ continue
231
+ }
232
+
235
233
var tmp * paths.Path
236
234
if tmpFile , err := ioutil .TempFile ("" , "" ); err != nil {
237
235
return nil , fmt .Errorf ("creating temp file for index download: %s" , err )
@@ -659,22 +657,26 @@ func createInstance(ctx context.Context, getLibOnly bool) (*createInstanceResult
659
657
urls := []string {globals .DefaultIndexURL }
660
658
urls = append (urls , configuration .Settings .GetStringSlice ("board_manager.additional_urls" )... )
661
659
for _ , u := range urls {
662
- URL , err := url . Parse (u )
660
+ URL , err := utils . URLParse (u )
663
661
if err != nil {
664
662
logrus .Warnf ("Unable to parse index URL: %s, skip..." , u )
665
663
continue
666
664
}
667
665
668
- if err := res .Pm .LoadPackageIndex (URL ); err != nil {
669
- res .PlatformIndexErrors = append (res .PlatformIndexErrors , err .Error ())
670
- }
671
- }
666
+ if URL .Scheme == "file" {
667
+ path := paths .New (URL .Path )
668
+ if err != nil {
669
+ return nil , fmt .Errorf ("can't get absolute path of %v: %w" , path , err )
670
+ }
672
671
673
- for _ , x := range configuration .Settings .GetStringSlice ("board_manager.additional_paths" ) {
674
- pathJSON , _ := paths .New (x ).Abs ()
672
+ _ , err = res .Pm .LoadPackageIndexFromFile (path )
673
+ if err != nil {
674
+ res .PlatformIndexErrors = append (res .PlatformIndexErrors , err .Error ())
675
+ }
676
+ continue
677
+ }
675
678
676
- _ , err := res .Pm .LoadPackageIndexFromFile (pathJSON )
677
- if err != nil {
679
+ if err := res .Pm .LoadPackageIndex (URL ); err != nil {
678
680
res .PlatformIndexErrors = append (res .PlatformIndexErrors , err .Error ())
679
681
}
680
682
}
0 commit comments