Skip to content

Do not fail if downloaded file has good checksum but incorrect size. #2739

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 3 commits into from
Oct 28, 2024
Merged
Changes from 1 commit
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
Next Next commit
Do not fail download if archive size do not match package_index.json …
…size (checksum is sufficient)
  • Loading branch information
cmaglie committed Oct 28, 2024
commit e1e524097824366ca21b274e24f57e5872d237ba
18 changes: 9 additions & 9 deletions internal/arduino/resources/checksums.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/arduino/arduino-cli/internal/i18n"
paths "github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
)

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

// TestLocalArchiveSize test if the local archive size match the DownloadResource size
func (r *DownloadResource) TestLocalArchiveSize(downloadDir *paths.Path) (bool, error) {
func (r *DownloadResource) TestLocalArchiveSize(downloadDir *paths.Path) error {
filePath, err := r.ArchivePath(downloadDir)
if err != nil {
return false, errors.New(i18n.Tr("getting archive path: %s", err))
return errors.New(i18n.Tr("getting archive path: %s", err))
}
info, err := filePath.Stat()
if err != nil {
return false, errors.New(i18n.Tr("getting archive info: %s", err))
return errors.New(i18n.Tr("getting archive info: %s", err))
}
// If the size do not match, just report a warning and continue
// (the checksum is sufficient to ensure the integrity of the archive)
if info.Size() != r.Size {
return false, fmt.Errorf("%s: %d != %d", i18n.Tr("fetched archive size differs from size specified in index"), info.Size(), r.Size)
logrus.Warningf("%s: %d != %d", i18n.Tr("fetched archive size differs from size specified in index"), info.Size(), r.Size)
}

return true, nil
return nil
}

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

if ok, err := r.TestLocalArchiveSize(downloadDir); err != nil {
if err := r.TestLocalArchiveSize(downloadDir); err != nil {
return false, errors.New(i18n.Tr("testing archive size: %s", err))
} else if !ok {
return false, nil
}

ok, err := r.TestLocalArchiveChecksum(downloadDir)
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy