Skip to content

Commit e1e5240

Browse files
committed
Do not fail download if archive size do not match package_index.json size (checksum is sufficient)
1 parent 2dcee40 commit e1e5240

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

internal/arduino/resources/checksums.go

+9-9
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-
return false, 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)

0 commit comments

Comments
 (0)