mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
internal/download: distinguish missing file from stale file in era download
When downloading era files, all files are reported as "stale" even when they simply haven't been downloaded yet. This is confusing because "stale" implies the file exists but has a mismatched hash. The root cause is that verifyHash returns an error for both cases (file not found and hash mismatch), and DownloadFile unconditionally prints "is stale" for any error. Distinguish the two cases by checking os.IsNotExist on the error from verifyHash: print "not found, downloading" for missing files and "is stale" only for files with a mismatched hash. Fixes #31917
This commit is contained in:
parent
723aae2b4e
commit
781b51893f
1 changed files with 5 additions and 3 deletions
|
|
@ -180,12 +180,14 @@ 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 {
|
||||
if err := verifyHash(dstPath, hash); err == nil {
|
||||
fmt.Printf("%s is up-to-date\n", dstPath)
|
||||
return nil
|
||||
} else if os.IsNotExist(err) {
|
||||
fmt.Printf("%s not found, downloading\n", dstPath)
|
||||
} else {
|
||||
fmt.Printf("%s is stale\n", dstPath)
|
||||
}
|
||||
|
||||
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