Skip to content

Fix update indexes running when not necessary #1063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions cli/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ package instance

import (
"context"
"fmt"
"strings"

"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/configuration"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/arduino/go-paths-helper"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -51,9 +55,13 @@ func getInitResponse() (*rpc.InitResp, error) {
return nil, errors.Wrap(err, "creating instance")
}

// Init() succeeded but there were errors loading library indexes,
// let's rescan and try again
if resp.GetLibrariesIndexError() != "" {
// Gets the data directory to verify if library_index.json and package_index.json exist
dataDir := paths.New(configuration.Settings.GetString("directories.data"))

// The library_index.json file doesn't exists, that means the CLI is run for the first time
// so we proceed with the first update that downloads the file
libraryIndex := dataDir.Join("library_index.json")
if libraryIndex.NotExist() {
logrus.Warnf("There were errors loading the library index, trying again...")

// update all indexes
Expand All @@ -80,15 +88,11 @@ func getInitResponse() (*rpc.InitResp, error) {
resp.PlatformsIndexErrors = rescanResp.PlatformsIndexErrors
}

// Init() succeeded but there were errors loading platform indexes,
// let's rescan and try again
if resp.GetPlatformsIndexErrors() != nil {

// log each error
for _, err := range resp.GetPlatformsIndexErrors() {
logrus.Errorf("Error loading platform index: %v", err)
}

// The package_index.json file doesn't exists, that means the CLI is run for the first time,
// similarly to the library update we download that file and all the other package indexes
// from additional_urls
packageIndex := dataDir.Join("package_index.json")
if packageIndex.NotExist() {
// update platform index
_, err := commands.UpdateIndex(context.Background(),
&rpc.UpdateIndexReq{Instance: resp.GetInstance()}, output.ProgressBar())
Expand Down Expand Up @@ -124,8 +128,7 @@ func checkPlatformErrors(resp *rpc.InitResp) error {
for _, err := range resp.GetPlatformsIndexErrors() {
logrus.Errorf("Error loading platform index: %v", err)
}
// return
return errors.New("There were errors loading platform indexes")
return fmt.Errorf("error loading platform index: \n%v", strings.Join(resp.GetPlatformsIndexErrors(), "\n"))
}

return nil
Expand Down
5 changes: 5 additions & 0 deletions commands/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package commands

import (
"errors"
"time"

"github.com/arduino/arduino-cli/httpclient"
Expand Down Expand Up @@ -60,6 +61,10 @@ func Download(d *downloader.Downloader, label string, downloadCB DownloadProgres
if d.Error() != nil {
return d.Error()
}
// The URL is not reachable for some reason
if d.Resp.StatusCode >= 400 && d.Resp.StatusCode <= 599 {
return errors.New(d.Resp.Status)
}
downloadCB(&rpc.DownloadProgress{Completed: true})
return nil
}
6 changes: 3 additions & 3 deletions commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo
return nil, fmt.Errorf("downloading index %s: %s", URL, err)
}
coreIndexPath := indexpath.Join(path.Base(URL.Path))
Download(d, "Updating index: "+coreIndexPath.Base(), downloadCB)
if d.Error() != nil {
return nil, fmt.Errorf("downloading index %s: %s", URL, d.Error())
err = Download(d, "Updating index: "+coreIndexPath.Base(), downloadCB)
if err != nil {
return nil, fmt.Errorf("downloading index %s: %s", URL, err)
}

// Check for signature
Expand Down
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ require (
github.com/h2non/filetype v1.0.8 // indirect
github.com/imjasonmiller/godice v0.1.2
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leonelquinteros/gotext v1.4.0
github.com/marcinbor85/gohex v0.0.0-20200531163658-baab2527a9a2
github.com/mattn/go-colorable v0.1.2
github.com/mattn/go-isatty v0.0.8
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/miekg/dns v1.0.5 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/oleksandr/bonjour v0.0.0-20160508152359-5dcf00d8b228 // indirect
github.com/pkg/errors v0.9.1
github.com/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583
Expand All @@ -40,11 +37,10 @@ require (
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v1.0.1-0.20200710201246-675ae5f5a98c
github.com/spf13/jwalterweatherman v1.0.0
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.6.2
github.com/stretchr/testify v1.6.1
go.bug.st/cleanup v1.0.0
go.bug.st/downloader/v2 v2.0.1
go.bug.st/downloader/v2 v2.1.0
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18
go.bug.st/serial v1.1.1
go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 // indirect
Expand All @@ -53,7 +49,6 @@ require (
golang.org/x/text v0.3.2
google.golang.org/grpc v1.27.0
google.golang.org/protobuf v1.25.0
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v2 v2.3.0
Expand Down
Loading