Skip to content

Fixed some error messages/warnings during index download #2257

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
Aug 3, 2023
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
5 changes: 5 additions & 0 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sync"
"time"

"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
"github.com/arduino/arduino-cli/arduino/discovery/discoverymanager"
Expand All @@ -34,6 +35,7 @@ import (
paths "github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
"github.com/arduino/go-timeutils"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
semver "go.bug.st/relaxed-semver"
)
Expand Down Expand Up @@ -438,6 +440,9 @@ func (pme *Explorer) determineReferencedPlatformRelease(boardBuildProperties *pr
// LoadPackageIndex loads a package index by looking up the local cached file from the specified URL
func (pmb *Builder) LoadPackageIndex(URL *url.URL) error {
indexFileName := path.Base(URL.Path)
if indexFileName == "." || indexFileName == "" {
return &arduino.InvalidURLError{Cause: errors.New(URL.String())}
}
if strings.HasSuffix(indexFileName, ".tar.bz2") {
indexFileName = strings.TrimSuffix(indexFileName, ".tar.bz2") + ".json"
}
Expand Down
12 changes: 9 additions & 3 deletions arduino/resources/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ type IndexResource struct {
}

// IndexFileName returns the index file name as it is saved in data dir (package_xxx_index.json).
func (res *IndexResource) IndexFileName() string {
func (res *IndexResource) IndexFileName() (string, error) {
filename := path.Base(res.URL.Path) // == package_index.json[.gz] || packacge_index.tar.bz2
if filename == "." || filename == "" {
return "", &arduino.InvalidURLError{}
}
if i := strings.Index(filename, "."); i != -1 {
filename = filename[:i]
}
return filename + ".json"
return filename + ".json", nil
}

// Download will download the index and possibly check the signature using the Arduino's public key.
Expand All @@ -63,7 +66,10 @@ func (res *IndexResource) Download(destDir *paths.Path, downloadCB rpc.DownloadP

// Download index file
downloadFileName := path.Base(res.URL.Path) // == package_index.json[.gz] || package_index.tar.bz2
indexFileName := res.IndexFileName() // == package_index.json
indexFileName, err := res.IndexFileName() // == package_index.json
if err != nil {
return err
}
tmpIndexPath := tmp.Join(downloadFileName)
if err := httpclient.DownloadFile(tmpIndexPath, res.URL.String(), "", tr("Downloading index: %s", downloadFileName), downloadCB, nil, downloader.NoResume); err != nil {
return &arduino.FailedDownloadError{Message: tr("Error downloading index '%s'", res.URL), Cause: err}
Expand Down
16 changes: 14 additions & 2 deletions commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,14 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
allPackageIndexUrls = append(allPackageIndexUrls, URL)
}
}
firstUpdate(context.Background(), req.GetInstance(), downloadCallback, allPackageIndexUrls)
if err := firstUpdate(context.Background(), req.GetInstance(), downloadCallback, allPackageIndexUrls); err != nil {
e := &arduino.InitFailedError{
Code: codes.InvalidArgument,
Cause: err,
Reason: rpc.FailedInstanceInitReason_FAILED_INSTANCE_INIT_REASON_INDEX_DOWNLOAD_ERROR,
}
responseError(e.ToRPCStatus())
}

{
// We need to rebuild the PackageManager currently in use by this instance
Expand Down Expand Up @@ -589,7 +596,12 @@ func firstUpdate(ctx context.Context, instance *rpc.Instance, downloadCb func(ms
if URL.Scheme == "file" {
continue
}
packageIndexFileName := (&resources.IndexResource{URL: URL}).IndexFileName()
packageIndexFileName, err := (&resources.IndexResource{URL: URL}).IndexFileName()
if err != nil {
return &arduino.FailedDownloadError{
Message: tr("Error downloading index '%s'", URL),
Cause: &arduino.InvalidURLError{}}
}
packageIndexFile := dataDir.Join(packageIndexFileName)
if packageIndexFile.NotExist() {
// The index file doesn't exists, that means the CLI is run for the first time,
Expand Down
Loading