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:
YQ AltLayer 2026-03-01 12:41:57 +00:00
parent 723aae2b4e
commit 781b51893f

View file

@ -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 {