From 1d4657b614a59b6ed134369db70df9ccae6e6d41 Mon Sep 17 00:00:00 2001 From: Ayush Baluni <73417844+aayushbaluni@users.noreply.github.com> Date: Wed, 18 Mar 2026 11:39:32 +0530 Subject: [PATCH] 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 --- internal/download/download.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/download/download.go b/internal/download/download.go index c59c8a90c3..3419a85a9e 100644 --- a/internal/download/download.go +++ b/internal/download/download.go @@ -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 {