Skip to content

Commit 45b1ad9

Browse files
committed
Simplified cores index update function
1 parent 7f348ad commit 45b1ad9

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

commands/core/update_index.go

+7-25
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@
3030
package core
3131

3232
import (
33-
"net/url"
3433
"os"
3534

3635
"github.com/bcmi-labs/arduino-cli/commands"
3736

3837
"github.com/bcmi-labs/arduino-cli/common"
3938
"github.com/bcmi-labs/arduino-cli/common/formatter"
4039
"github.com/bcmi-labs/arduino-cli/configs"
41-
"github.com/bcmi-labs/arduino-cli/task"
4240
"github.com/sirupsen/logrus"
4341
"github.com/spf13/cobra"
4442
)
@@ -59,35 +57,19 @@ var updateIndexCommand = &cobra.Command{
5957
func runUpdateIndexCommand(cmd *cobra.Command, args []string) {
6058
logrus.Info("Updating package index")
6159

62-
downloadTasks := []task.Task{}
63-
ignoreWarns := []bool{}
64-
for _, URL := range configs.BoardManagerAdditionalUrls {
65-
msgs := &formatter.TaskWrapperMessages{
66-
BeforeMessage: "Downloading package index from " + URL.String(),
67-
ErrorMessage: "Can't download index file, check your network connection.",
68-
}
69-
task := formatter.WrapTask(downloadTask(URL), msgs)
70-
downloadTasks = append(downloadTasks, task)
71-
ignoreWarns = append(ignoreWarns, false)
72-
}
73-
74-
results := task.ExecuteSequence(downloadTasks, ignoreWarns)
7560
failed := false
76-
for _, result := range results {
77-
if result.Error != nil {
78-
formatter.PrintError(result.Error, "Error downloading package index")
61+
for _, URL := range configs.BoardManagerAdditionalUrls {
62+
formatter.Print("Downloading package index from " + URL.String())
63+
coreIndexPath := configs.IndexPathFromURL(URL)
64+
if err := common.DownloadIndex(coreIndexPath, URL); err != nil {
65+
formatter.PrintError(err, "Can't download index file.")
7966
failed = true
8067
}
8168
}
69+
8270
if failed {
71+
formatter.PrintErrorMessage("Error downloading package index, check your network connection")
8372
os.Exit(commands.ErrNetwork)
8473
}
8574
formatter.Print("Download completed.")
8675
}
87-
88-
func downloadTask(packageIndexURL *url.URL) task.Task {
89-
coreIndexPath := configs.IndexPathFromURL(packageIndexURL)
90-
return func() task.Result {
91-
return task.Result{Error: common.DownloadIndex(coreIndexPath, packageIndexURL)}
92-
}
93-
}

common/net_functions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import (
4646
func DownloadIndex(indexPath pathutils.Path, URL *url.URL) error {
4747
file, err := indexPath.Get()
4848
if err != nil {
49-
return err
49+
return fmt.Errorf("getting index path: %s", err)
5050
}
5151

5252
req, err := http.NewRequest("GET", URL.String(), nil)

0 commit comments

Comments
 (0)