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

Sign up
Appearance settings

Commit 7ee4cf7

Browse files
authored
Do not fail if downloaded file has good checksum but incorrect size. (#2739)
* Do not fail download if archive size do not match package_index.json size (checksum is sufficient) * Added unit tests * Added integration test
1 parent 2dcee40 commit 7ee4cf7

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

‎internal/arduino/resources/checksums.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
"github.com/arduino/arduino-cli/internal/i18n"
3333
paths "github.com/arduino/go-paths-helper"
34+
"github.com/sirupsen/logrus"
3435
)
3536

3637
// TestLocalArchiveChecksum test if the checksum of the local archive match the checksum of the DownloadResource
@@ -82,20 +83,21 @@ func (r *DownloadResource) TestLocalArchiveChecksum(downloadDir *paths.Path) (bo
8283
}
8384

8485
// TestLocalArchiveSize test if the local archive size match the DownloadResource size
85-
func (r *DownloadResource) TestLocalArchiveSize(downloadDir *paths.Path) (bool, error) {
86+
func (r *DownloadResource) TestLocalArchiveSize(downloadDir *paths.Path) error {
8687
filePath, err := r.ArchivePath(downloadDir)
8788
if err != nil {
88-
return false, errors.New(i18n.Tr("getting archive path: %s", err))
89+
return errors.New(i18n.Tr("getting archive path: %s", err))
8990
}
9091
info, err := filePath.Stat()
9192
if err != nil {
92-
return false, errors.New(i18n.Tr("getting archive info: %s", err))
93+
return errors.New(i18n.Tr("getting archive info: %s", err))
9394
}
95+
// If the size do not match, just report a warning and continue
96+
// (the checksum is sufficient to ensure the integrity of the archive)
9497
if info.Size() != r.Size {
95-
returnfalse, fmt.Errorf("%s: %d != %d", i18n.Tr("fetched archive size differs from size specified in index"), info.Size(), r.Size)
98+
logrus.Warningf("%s: %d != %d", i18n.Tr("fetched archive size differs from size specified in index"), info.Size(), r.Size)
9699
}
97-
98-
return true, nil
100+
return nil
99101
}
100102

101103
// TestLocalArchiveIntegrity checks for integrity of the local archive.
@@ -106,10 +108,8 @@ func (r *DownloadResource) TestLocalArchiveIntegrity(downloadDir *paths.Path) (b
106108
return false, nil
107109
}
108110

109-
if ok, err := r.TestLocalArchiveSize(downloadDir); err != nil {
111+
if err := r.TestLocalArchiveSize(downloadDir); err != nil {
110112
return false, errors.New(i18n.Tr("testing archive size: %s", err))
111-
} else if !ok {
112-
return false, nil
113113
}
114114

115115
ok, err := r.TestLocalArchiveChecksum(downloadDir)

‎internal/arduino/resources/resources_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ func TestDownloadAndChecksums(t *testing.T) {
8282
require.NoError(t, err)
8383
downloadAndTestChecksum()
8484

85+
require.NoError(t, r.TestLocalArchiveSize(tmp))
86+
r.Size = 500
87+
require.NoError(t, r.TestLocalArchiveSize(tmp))
88+
8589
r.Checksum = ""
8690
_, err = r.TestLocalArchiveChecksum(tmp)
8791
require.Error(t, err)

‎internal/integrationtest/core/core_test.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,3 +1354,15 @@ func TestReferencedCoreBuildAndRuntimeProperties(t *testing.T) {
13541354
out.ArrayMustContain(jsonEncode("runtime.platform.path=" + corePlatformPath))
13551355
}
13561356
}
1357+
1358+
func TestCoreInstallWithWrongArchiveSize(t *testing.T) {
1359+
// See: https://github.com/arduino/arduino-cli/issues/2332
1360+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
1361+
defer env.CleanUp()
1362+
1363+
_, _, err := cli.Run("--additional-urls", "https://raw.githubusercontent.com/geolink/opentracker-arduino-board/bf6158ebab0402db217bfb02ea61461ddc6f2940/package_opentracker_index.json", "core", "update-index")
1364+
require.NoError(t, err)
1365+
1366+
_, _, err = cli.Run("--additional-urls", "https://raw.githubusercontent.com/geolink/opentracker-arduino-board/bf6158ebab0402db217bfb02ea61461ddc6f2940/package_opentracker_index.json", "core", "install", "opentracker:sam@1.0.5")
1367+
require.NoError(t, err)
1368+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /