Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c666277

Browse filesBrowse files
[skip-changelog] Add query parameters to urls generated by lib commands (#2034)
* Add query parameters to urls generated by lib commands * Add test to check query parameters * Fix comments on functions to make them clearer
1 parent b3e8f8a commit c666277
Copy full SHA for c666277

File tree

Expand file treeCollapse file tree

15 files changed

+89
-27
lines changed
Filter options
Expand file treeCollapse file tree

15 files changed

+89
-27
lines changed

‎arduino/cores/packagemanager/download.go

Copy file name to clipboardExpand all lines: arduino/cores/packagemanager/download.go
+2-2Lines changed: 2 additions & 2 deletions
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
}

‎arduino/cores/packagemanager/profiles.go

Copy file name to clipboardExpand all lines: arduino/cores/packagemanager/profiles.go
+1-1Lines changed: 1 addition & 1 deletion
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
}

‎arduino/httpclient/httpclient.go

Copy file name to clipboardExpand all lines: arduino/httpclient/httpclient.go
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ 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+
// If a not empty queryParameter is passed, it is appended to the URL for analysis purposes.
37+
func DownloadFile(path *paths.Path, URL string, queryParameter string, label string, downloadCB rpc.DownloadProgressCB, config *downloader.Config, options ...downloader.DownloadOptions) (returnedError error) {
38+
if queryParameter != "" {
39+
URL = URL + "?query=" + queryParameter
40+
}
41+
logrus.WithField("url", URL).Info("Starting download")
3642
downloadCB.Start(URL, label)
3743
defer func() {
3844
if returnedError == nil {

‎arduino/resources/download.go

Copy file name to clipboardExpand all lines: arduino/resources/download.go
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ 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+
// queryParameter is passed for analysis purposes.
31+
func (r *DownloadResource) Download(downloadDir *paths.Path, config *downloader.Config, label string, downloadCB rpc.DownloadProgressCB, queryParameter string) error {
3132
path, err := r.ArchivePath(downloadDir)
3233
if err != nil {
3334
return fmt.Errorf(tr("getting archive path: %s"), err)
@@ -51,5 +52,5 @@ func (r *DownloadResource) Download(downloadDir *paths.Path, config *downloader.
5152
} else {
5253
return fmt.Errorf(tr("getting archive file info: %s"), err)
5354
}
54-
return httpclient.DownloadFile(path, r.URL, label, downloadCB, config)
55+
return httpclient.DownloadFile(path, r.URL, queryParameter, label, downloadCB, config)
5556
}

‎arduino/resources/helpers_test.go

Copy file name to clipboardExpand all lines: arduino/resources/helpers_test.go
+1-1Lines changed: 1 addition & 1 deletion
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

‎arduino/resources/index.go

Copy file name to clipboardExpand all lines: arduino/resources/index.go
+2-2Lines changed: 2 additions & 2 deletions
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

‎arduino/resources/resources_test.go

Copy file name to clipboardExpand all lines: arduino/resources/resources_test.go
+2-2Lines changed: 2 additions & 2 deletions
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)

‎commands/daemon/daemon.go

Copy file name to clipboardExpand all lines: commands/daemon/daemon.go
+2Lines changed: 2 additions & 0 deletions
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)

‎commands/instances.go

Copy file name to clipboardExpand all lines: commands/instances.go
+1-1Lines changed: 1 addition & 1 deletion
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())

‎commands/lib/download.go

Copy file name to clipboardExpand all lines: commands/lib/download.go
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ import (
3030

3131
var tr = i18n.Tr
3232

33-
// LibraryDownload FIXMEDOC
34-
func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.LibraryDownloadResponse, error) {
33+
// LibraryDownload executes the download of the library.
34+
// A DownloadProgressCB callback function must be passed to monitor download progress.
35+
// queryParameter is passed for analysis purposes.
36+
func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB, queryParameter string) (*rpc.LibraryDownloadResponse, error) {
3537
logrus.Info("Executing `arduino-cli lib download`")
3638

3739
lm := commands.GetLibraryManager(req)
@@ -46,22 +48,22 @@ func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downl
4648
return nil, err
4749
}
4850

49-
if err := downloadLibrary(lm, lib, downloadCB, func(*rpc.TaskProgress) {}); err != nil {
51+
if err := downloadLibrary(lm, lib, downloadCB, func(*rpc.TaskProgress) {}, queryParameter); err != nil {
5052
return nil, err
5153
}
5254

5355
return &rpc.LibraryDownloadResponse{}, nil
5456
}
5557

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

5961
taskCB(&rpc.TaskProgress{Name: tr("Downloading %s", libRelease)})
6062
config, err := httpclient.GetDownloaderConfig()
6163
if err != nil {
6264
return &arduino.FailedDownloadError{Message: tr("Can't download library"), Cause: err}
6365
}
64-
if err := libRelease.Resource.Download(lm.DownloadsDir, config, libRelease.String(), downloadCB); err != nil {
66+
if err := libRelease.Resource.Download(lm.DownloadsDir, config, libRelease.String(), downloadCB, queryParameter); err != nil {
6567
return &arduino.FailedDownloadError{Message: tr("Can't download library"), Cause: err}
6668
}
6769
taskCB(&rpc.TaskProgress{Completed: true})

‎commands/lib/install.go

Copy file name to clipboardExpand all lines: commands/lib/install.go
+18-7Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import (
3030
"github.com/sirupsen/logrus"
3131
)
3232

33-
// LibraryInstall FIXMEDOC
34-
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
33+
// LibraryInstall resolves the library dependencies, then downloads and installs the libraries into the install location.
34+
// queryParameter is passed for analysis purposes and forwarded to the called functions. It is set to "depends" when a dependency is installed
35+
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB, queryParameter string) error {
3536
lm := commands.GetLibraryManager(req)
3637
if lm == nil {
3738
return &arduino.InvalidInstanceError{}
@@ -96,11 +97,21 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
9697
}
9798

9899
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
100+
// Checks if libRelease is the requested library and not a dependency
101+
if libRelease.GetName() == req.Name {
102+
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, queryParameter); err != nil {
103+
return err
104+
}
105+
if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
106+
return err
107+
}
108+
} else {
109+
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, "depends"); err != nil {
110+
return err
111+
}
112+
if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
113+
return err
114+
}
104115
}
105116
}
106117

‎commands/lib/upgrade.go

Copy file name to clipboardExpand all lines: commands/lib/upgrade.go
+1-1Lines changed: 1 addition & 1 deletion
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
}

‎internal/cli/lib/download.go

Copy file name to clipboardExpand all lines: internal/cli/lib/download.go
+1-1Lines changed: 1 addition & 1 deletion
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(), "download")
6464
if err != nil {
6565
feedback.Fatal(tr("Error downloading %[1]s: %[2]v", library, err), feedback.ErrNetwork)
6666
}

‎internal/cli/lib/install.go

Copy file name to clipboardExpand all lines: internal/cli/lib/install.go
+1-1Lines changed: 1 addition & 1 deletion
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
}

‎internal/integrationtest/lib/lib_test.go

Copy file name to clipboardExpand all lines: internal/integrationtest/lib/lib_test.go
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,3 +1480,43 @@ func TestInstallWithGitUrlLocalFileUri(t *testing.T) {
14801480
// Verifies library is installed
14811481
require.DirExists(t, libInstallDir.String())
14821482
}
1483+
1484+
func TestLibQueryParameters(t *testing.T) {
1485+
// This test should not use shared download directory because it needs to download the libraries from scratch
1486+
env := integrationtest.NewEnvironment(t)
1487+
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
1488+
ArduinoCLIPath: integrationtest.FindArduinoCLIPath(t),
1489+
})
1490+
defer env.CleanUp()
1491+
1492+
// Updates index for cores and libraries
1493+
_, _, err := cli.Run("core", "update-index")
1494+
require.NoError(t, err)
1495+
_, _, err = cli.Run("lib", "update-index")
1496+
require.NoError(t, err)
1497+
1498+
// Check query=install when a library is installed
1499+
stdout, _, err := cli.Run("lib", "install", "USBHost@1.0.0", "-v", "--log-level", "debug")
1500+
require.NoError(t, err)
1501+
require.Contains(t, string(stdout),
1502+
"Starting download \x1b[36murl\x1b[0m=\"https://downloads.arduino.cc/libraries/github.com/arduino-libraries/USBHost-1.0.0.zip?query=install\"\n")
1503+
1504+
// Check query=upgrade when a library is upgraded
1505+
stdout, _, err = cli.Run("lib", "upgrade", "USBHost", "-v", "--log-level", "debug")
1506+
require.NoError(t, err)
1507+
require.Contains(t, string(stdout),
1508+
"Starting download \x1b[36murl\x1b[0m=\"https://downloads.arduino.cc/libraries/github.com/arduino-libraries/USBHost-1.0.5.zip?query=upgrade\"\n")
1509+
1510+
// Check query=depends when a library dependency is installed
1511+
stdout, _, err = cli.Run("lib", "install", "MD_Parola@3.5.5", "-v", "--log-level", "debug")
1512+
require.NoError(t, err)
1513+
require.Contains(t, string(stdout),
1514+
"Starting download \x1b[36murl\x1b[0m=\"https://downloads.arduino.cc/libraries/github.com/MajicDesigns/MD_MAX72XX-3.3.1.zip?query=depends\"\n")
1515+
1516+
// Check query=download when a library is downloaded
1517+
stdout, _, err = cli.Run("lib", "download", "WiFi101@0.16.1", "-v", "--log-level", "debug")
1518+
require.NoError(t, err)
1519+
require.Contains(t, string(stdout),
1520+
"Starting download \x1b[36murl\x1b[0m=\"https://downloads.arduino.cc/libraries/github.com/arduino-libraries/WiFi101-0.16.1.zip?query=download\"\n")
1521+
1522+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.