mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 01:41:36 +00:00
internal/download: distinguish missing file from stale in era download
verifyHash returns an error for both file-not-found (os.Open) and hash mismatch. DownloadFile previously printed 'is stale' for any error. Check errors.Is(err, os.ErrNotExist) to distinguish: - File missing: print 'not found, downloading' - Hash mismatch: print 'is stale' Fixes #31917
This commit is contained in:
parent
ab357151da
commit
1d4657b614
1 changed files with 8 additions and 3 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"iter"
|
||||
|
|
@ -180,12 +181,16 @@ func (db *ChecksumDB) DownloadFile(url, dstPath string) error {
|
|||
return fmt.Errorf("no known hash for file %q", basename)
|
||||
}
|
||||
// Shortcut if already downloaded.
|
||||
if verifyHash(dstPath, hash) == nil {
|
||||
verifyErr := verifyHash(dstPath, hash)
|
||||
if verifyErr == nil {
|
||||
fmt.Printf("%s is up-to-date\n", dstPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("%s is stale\n", dstPath)
|
||||
if errors.Is(verifyErr, os.ErrNotExist) {
|
||||
fmt.Printf("%s not found, downloading\n", dstPath)
|
||||
} else {
|
||||
fmt.Printf("%s is stale\n", dstPath)
|
||||
}
|
||||
fmt.Printf("downloading from %s\n", url)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue