Skip to content
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

store: add functions to download snap icons #14990

Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
14 changes: 11 additions & 3 deletions store/store_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,17 @@ func downloadIconImpl(ctx context.Context, name, downloadURL string, w io.ReadWr
default:
return &DownloadError{Code: resp.StatusCode, URL: resp.Request.URL}
}
if resp.ContentLength == 0 {
logger.Debugf("Unexpected Content-Length: 0 for %s", downloadURL)

const maxIconFilesize int64 = 300000

if resp.ContentLength == 0 || resp.ContentLength > maxIconFilesize {
return fmt.Errorf("unsupported Content-Length for %s (must be nonzero and <%dB): %d", downloadURL, maxIconFilesize, resp.ContentLength)
} else {
logger.Debugf("Download size for %s: %d", downloadURL, resp.ContentLength)
}

_, finalErr = io.Copy(w, resp.Body)
var bytesWritten int64
bytesWritten, finalErr = io.Copy(w, resp.Body)
olivercalder marked this conversation as resolved.
Show resolved Hide resolved

if cancelled(ctx) {
return fmt.Errorf("the download has been cancelled: %s", ctx.Err())
Expand All @@ -715,10 +719,14 @@ func downloadIconImpl(ctx context.Context, name, downloadURL string, w io.ReadWr
if httputil.ShouldRetryAttempt(attempt, finalErr) {
// XXX: is this correct, without resume? Or should we just
// error here since we're not doing Range requests?
// And should we seek w back to 0?
continue
}
break
olivercalder marked this conversation as resolved.
Show resolved Hide resolved
}
if bytesWritten > maxIconFilesize {
return fmt.Errorf("the download size exceeded the max icon filesize (%dB), despite that the reported Content-Length was %d: %d", maxIconFilesize, resp.ContentLength, bytesWritten)
}
break
}
if finalErr == nil {
Expand Down