Skip to content

Commit a34f72c

Browse files
Add query parameters to urls generated by lib commands
1 parent b3e8f8a commit a34f72c

File tree

14 files changed

+41
-25
lines changed

14 files changed

+41
-25
lines changed

Diff for: arduino/cores/packagemanager/download.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (pme *Explorer) DownloadToolRelease(tool *cores.ToolRelease, config *downlo
127127
Message: tr("Error downloading tool %s", tool),
128128
Cause: errors.New(tr("no versions available for the current OS"))}
129129
}
130-
return resource.Download(pme.DownloadDir, config, tool.String(), progressCB)
130+
return resource.Download(pme.DownloadDir, config, tool.String(), progressCB, "")
131131
}
132132

133133
// DownloadPlatformRelease downloads a PlatformRelease. If the platform is already downloaded a
@@ -136,5 +136,5 @@ func (pme *Explorer) DownloadPlatformRelease(platform *cores.PlatformRelease, co
136136
if platform.Resource == nil {
137137
return &arduino.PlatformNotFoundError{Platform: platform.String()}
138138
}
139-
return platform.Resource.Download(pme.DownloadDir, config, platform.String(), progressCB)
139+
return platform.Resource.Download(pme.DownloadDir, config, platform.String(), progressCB, "")
140140
}

Diff for: arduino/cores/packagemanager/profiles.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func (pmb *Builder) installMissingProfileTool(toolRelease *cores.ToolRelease, de
176176
return &arduino.InvalidVersionError{Cause: fmt.Errorf(tr("version %s not available for this operating system", toolRelease))}
177177
}
178178
taskCB(&rpc.TaskProgress{Name: tr("Downloading tool %s", toolRelease)})
179-
if err := toolResource.Download(pmb.DownloadDir, nil, toolRelease.String(), downloadCB); err != nil {
179+
if err := toolResource.Download(pmb.DownloadDir, nil, toolRelease.String(), downloadCB, ""); err != nil {
180180
taskCB(&rpc.TaskProgress{Name: tr("Error downloading tool %s", toolRelease)})
181181
return &arduino.FailedInstallError{Message: tr("Error installing tool %s", toolRelease), Cause: err}
182182
}

Diff for: arduino/httpclient/httpclient.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ import (
2525
"github.com/arduino/arduino-cli/i18n"
2626
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2727
"github.com/arduino/go-paths-helper"
28+
"github.com/sirupsen/logrus"
2829
"go.bug.st/downloader/v2"
2930
)
3031

3132
var tr = i18n.Tr
3233

3334
// DownloadFile downloads a file from a URL into the specified path. An optional config and options may be passed (or nil to use the defaults).
3435
// A DownloadProgressCB callback function must be passed to monitor download progress.
35-
func DownloadFile(path *paths.Path, URL string, label string, downloadCB rpc.DownloadProgressCB, config *downloader.Config, options ...downloader.DownloadOptions) (returnedError error) {
36+
func DownloadFile(path *paths.Path, URL string, queryParameter string, label string, downloadCB rpc.DownloadProgressCB, config *downloader.Config, options ...downloader.DownloadOptions) (returnedError error) {
37+
if queryParameter != "" {
38+
URL = URL + "?query=" + queryParameter
39+
}
40+
logrus.WithField("url", URL).Info("Starting download")
3641
downloadCB.Start(URL, label)
3742
defer func() {
3843
if returnedError == nil {

Diff for: arduino/resources/download.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727

2828
// Download performs a download loop using the provided downloader.Config.
2929
// Messages are passed back to the DownloadProgressCB using label as text for the File field.
30-
func (r *DownloadResource) Download(downloadDir *paths.Path, config *downloader.Config, label string, downloadCB rpc.DownloadProgressCB) error {
30+
func (r *DownloadResource) Download(downloadDir *paths.Path, config *downloader.Config, label string, downloadCB rpc.DownloadProgressCB, queryParameter string) error {
3131
path, err := r.ArchivePath(downloadDir)
3232
if err != nil {
3333
return fmt.Errorf(tr("getting archive path: %s"), err)
@@ -51,5 +51,5 @@ func (r *DownloadResource) Download(downloadDir *paths.Path, config *downloader.
5151
} else {
5252
return fmt.Errorf(tr("getting archive file info: %s"), err)
5353
}
54-
return httpclient.DownloadFile(path, r.URL, label, downloadCB, config)
54+
return httpclient.DownloadFile(path, r.URL, queryParameter, label, downloadCB, config)
5555
}

Diff for: arduino/resources/helpers_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) {
5656

5757
httpClient := httpclient.NewWithConfig(&httpclient.Config{UserAgent: goldUserAgentValue})
5858

59-
err = r.Download(tmp, &downloader.Config{HttpClient: *httpClient}, "", func(progress *rpc.DownloadProgress) {})
59+
err = r.Download(tmp, &downloader.Config{HttpClient: *httpClient}, "", func(progress *rpc.DownloadProgress) {}, "")
6060
require.NoError(t, err)
6161

6262
// leverage the download helper to download the echo for the request made by the downloader itself

Diff for: arduino/resources/index.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (res *IndexResource) Download(destDir *paths.Path, downloadCB rpc.DownloadP
5555
// Download index file
5656
indexFileName := path.Base(res.URL.Path) // == package_index.json[.gz]
5757
tmpIndexPath := tmp.Join(indexFileName)
58-
if err := httpclient.DownloadFile(tmpIndexPath, res.URL.String(), tr("Downloading index: %s", indexFileName), downloadCB, nil, downloader.NoResume); err != nil {
58+
if err := httpclient.DownloadFile(tmpIndexPath, res.URL.String(), "", tr("Downloading index: %s", indexFileName), downloadCB, nil, downloader.NoResume); err != nil {
5959
return &arduino.FailedDownloadError{Message: tr("Error downloading index '%s'", res.URL), Cause: err}
6060
}
6161

@@ -112,7 +112,7 @@ func (res *IndexResource) Download(destDir *paths.Path, downloadCB rpc.DownloadP
112112
// Download signature
113113
signaturePath = destDir.Join(signatureFileName)
114114
tmpSignaturePath = tmp.Join(signatureFileName)
115-
if err := httpclient.DownloadFile(tmpSignaturePath, res.SignatureURL.String(), tr("Downloading index signature: %s", signatureFileName), downloadCB, nil, downloader.NoResume); err != nil {
115+
if err := httpclient.DownloadFile(tmpSignaturePath, res.SignatureURL.String(), "", tr("Downloading index signature: %s", signatureFileName), downloadCB, nil, downloader.NoResume); err != nil {
116116
return &arduino.FailedDownloadError{Message: tr("Error downloading index signature '%s'", res.SignatureURL), Cause: err}
117117
}
118118

Diff for: arduino/resources/resources_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestDownloadAndChecksums(t *testing.T) {
4848
require.NoError(t, err)
4949

5050
downloadAndTestChecksum := func() {
51-
err := r.Download(tmp, &downloader.Config{}, "", func(*rpc.DownloadProgress) {})
51+
err := r.Download(tmp, &downloader.Config{}, "", func(*rpc.DownloadProgress) {}, "")
5252
require.NoError(t, err)
5353

5454
data, err := testFile.ReadFile()
@@ -62,7 +62,7 @@ func TestDownloadAndChecksums(t *testing.T) {
6262
downloadAndTestChecksum()
6363

6464
// Download with cached file
65-
err = r.Download(tmp, &downloader.Config{}, "", func(*rpc.DownloadProgress) {})
65+
err = r.Download(tmp, &downloader.Config{}, "", func(*rpc.DownloadProgress) {}, "")
6666
require.NoError(t, err)
6767

6868
// Download if cached file has data in excess (redownload)

Diff for: commands/daemon/daemon.go

+2
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ func (s *ArduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadRequest,
343343
resp, err := lib.LibraryDownload(
344344
stream.Context(), req,
345345
func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryDownloadResponse{Progress: p}) },
346+
"",
346347
)
347348
if err != nil {
348349
return convertErrorToRPCStatus(err)
@@ -356,6 +357,7 @@ func (s *ArduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, s
356357
stream.Context(), req,
357358
func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryInstallResponse{Progress: p}) },
358359
func(p *rpc.TaskProgress) { stream.Send(&rpc.LibraryInstallResponse{TaskProgress: p}) },
360+
"",
359361
)
360362
if err != nil {
361363
return convertErrorToRPCStatus(err)

Diff for: commands/instances.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
415415
responseError(err.ToRPCStatus())
416416
continue
417417
}
418-
if err := libRelease.Resource.Download(lm.DownloadsDir, nil, libRelease.String(), downloadCallback); err != nil {
418+
if err := libRelease.Resource.Download(lm.DownloadsDir, nil, libRelease.String(), downloadCallback, ""); err != nil {
419419
taskCallback(&rpc.TaskProgress{Name: tr("Error downloading library %s", libraryRef)})
420420
e := &arduino.FailedLibraryInstallError{Cause: err}
421421
responseError(e.ToRPCStatus())

Diff for: commands/lib/download.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
var tr = i18n.Tr
3232

3333
// LibraryDownload FIXMEDOC
34-
func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.LibraryDownloadResponse, error) {
34+
func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB, queryParameter string) (*rpc.LibraryDownloadResponse, error) {
3535
logrus.Info("Executing `arduino-cli lib download`")
3636

3737
lm := commands.GetLibraryManager(req)
@@ -46,22 +46,22 @@ func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downl
4646
return nil, err
4747
}
4848

49-
if err := downloadLibrary(lm, lib, downloadCB, func(*rpc.TaskProgress) {}); err != nil {
49+
if err := downloadLibrary(lm, lib, downloadCB, func(*rpc.TaskProgress) {}, queryParameter); err != nil {
5050
return nil, err
5151
}
5252

5353
return &rpc.LibraryDownloadResponse{}, nil
5454
}
5555

5656
func downloadLibrary(lm *librariesmanager.LibrariesManager, libRelease *librariesindex.Release,
57-
downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
57+
downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB, queryParameter string) error {
5858

5959
taskCB(&rpc.TaskProgress{Name: tr("Downloading %s", libRelease)})
6060
config, err := httpclient.GetDownloaderConfig()
6161
if err != nil {
6262
return &arduino.FailedDownloadError{Message: tr("Can't download library"), Cause: err}
6363
}
64-
if err := libRelease.Resource.Download(lm.DownloadsDir, config, libRelease.String(), downloadCB); err != nil {
64+
if err := libRelease.Resource.Download(lm.DownloadsDir, config, libRelease.String(), downloadCB, queryParameter); err != nil {
6565
return &arduino.FailedDownloadError{Message: tr("Can't download library"), Cause: err}
6666
}
6767
taskCB(&rpc.TaskProgress{Completed: true})

Diff for: commands/lib/install.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
// LibraryInstall FIXMEDOC
34-
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
34+
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB, queryParameter string) error {
3535
lm := commands.GetLibraryManager(req)
3636
if lm == nil {
3737
return &arduino.InvalidInstanceError{}
@@ -96,11 +96,20 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
9696
}
9797

9898
for libRelease, installTask := range libReleasesToInstall {
99-
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB); err != nil {
100-
return err
101-
}
102-
if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
103-
return err
99+
if libRelease.GetName() == req.Name {
100+
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, queryParameter); err != nil {
101+
return err
102+
}
103+
if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
104+
return err
105+
}
106+
} else {
107+
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, "depends"); err != nil {
108+
return err
109+
}
110+
if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
111+
return err
112+
}
104113
}
105114
}
106115

Diff for: commands/lib/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func upgrade(instance *rpc.Instance, libs []*installedLib, downloadCB rpc.Downlo
7373
NoDeps: false,
7474
NoOverwrite: false,
7575
}
76-
err := LibraryInstall(context.Background(), libInstallReq, downloadCB, taskCB)
76+
err := LibraryInstall(context.Background(), libInstallReq, downloadCB, taskCB, "upgrade")
7777
if err != nil {
7878
return err
7979
}

Diff for: internal/cli/lib/download.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func runDownloadCommand(cmd *cobra.Command, args []string) {
6060
Name: library.Name,
6161
Version: library.Version,
6262
}
63-
_, err := lib.LibraryDownload(context.Background(), libraryDownloadRequest, feedback.ProgressBar())
63+
_, err := lib.LibraryDownload(context.Background(), libraryDownloadRequest, feedback.ProgressBar(), "")
6464
if err != nil {
6565
feedback.Fatal(tr("Error downloading %[1]s: %[2]v", library, err), feedback.ErrNetwork)
6666
}

Diff for: internal/cli/lib/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
130130
NoDeps: noDeps,
131131
NoOverwrite: noOverwrite,
132132
}
133-
err := lib.LibraryInstall(context.Background(), libraryInstallRequest, feedback.ProgressBar(), feedback.TaskProgress())
133+
err := lib.LibraryInstall(context.Background(), libraryInstallRequest, feedback.ProgressBar(), feedback.TaskProgress(), "install")
134134
if err != nil {
135135
feedback.Fatal(tr("Error installing %s: %v", libRef.Name, err), feedback.ErrGeneric)
136136
}

0 commit comments

Comments
 (0)