mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 06:11:51 +08:00
Add checksums to SHA256 mismatch error message (#107461)
This should make it easier to debug this issue if we see it again.
This commit is contained in:
@ -100,7 +100,7 @@ func (c *Client) SendReq(ctx context.Context, url *url.URL, compatOpts CompatOpt
|
||||
return io.ReadAll(bodyReader)
|
||||
}
|
||||
|
||||
func (c *Client) downloadFile(ctx context.Context, tmpFile *os.File, pluginURL, checksum string, compatOpts CompatOpts) (err error) {
|
||||
func (c *Client) downloadFile(ctx context.Context, tmpFile *os.File, pluginURL, expectedChecksum string, compatOpts CompatOpts) (err error) {
|
||||
// Try handling URL as a local file path first
|
||||
if _, err := os.Stat(pluginURL); err == nil {
|
||||
// TODO re-verify
|
||||
@ -136,7 +136,7 @@ func (c *Client) downloadFile(ctx context.Context, tmpFile *os.File, pluginURL,
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = c.downloadFile(ctx, tmpFile, pluginURL, checksum, compatOpts)
|
||||
err = c.downloadFile(ctx, tmpFile, pluginURL, expectedChecksum, compatOpts)
|
||||
} else {
|
||||
c.retryCount = 0
|
||||
failure := fmt.Sprintf("%v", r)
|
||||
@ -169,7 +169,7 @@ func (c *Client) downloadFile(ctx context.Context, tmpFile *os.File, pluginURL,
|
||||
if c.retryCount < 3 {
|
||||
c.retryCount++
|
||||
c.log.Debug("Failed downloading. Will retry.")
|
||||
err = c.downloadFile(ctx, tmpFile, pluginURL, checksum, compatOpts)
|
||||
err = c.downloadFile(ctx, tmpFile, pluginURL, expectedChecksum, compatOpts)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -187,8 +187,9 @@ func (c *Client) downloadFile(ctx context.Context, tmpFile *os.File, pluginURL,
|
||||
if err = w.Flush(); err != nil {
|
||||
return fmt.Errorf("failed to write to %q: %w", tmpFile.Name(), err)
|
||||
}
|
||||
if len(checksum) > 0 && checksum != fmt.Sprintf("%x", h.Sum(nil)) {
|
||||
return ErrChecksumMismatch(pluginURL)
|
||||
computedChecksum := fmt.Sprintf("%x", h.Sum(nil))
|
||||
if len(expectedChecksum) > 0 && expectedChecksum != computedChecksum {
|
||||
return ErrChecksumMismatch(pluginURL, expectedChecksum, computedChecksum)
|
||||
}
|
||||
|
||||
c.retryCount = 0
|
||||
|
Reference in New Issue
Block a user