From b92c86deb79dff0338545b0a530442b2c7abf36c Mon Sep 17 00:00:00 2001 From: Rahman Date: Wed, 6 May 2026 07:02:03 -0600 Subject: [PATCH] internal/download: don't discard `dst.Close` error (#34866) When `io.Copy` succeeds but the buffered `Close` fails (e.g. disk full on `Flush`), the error was swallowed and verification reported a misleading hash mismatch instead of the real I/O failure. Keep the `Close` error when `io.Copy` didn't already produce one. --------- Co-authored-by: Jared Wasinger --- internal/download/download.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/download/download.go b/internal/download/download.go index 79cf27a56b..27d3732731 100644 --- a/internal/download/download.go +++ b/internal/download/download.go @@ -211,9 +211,11 @@ func (db *ChecksumDB) DownloadFile(url, dstPath string) error { if resp.ContentLength > 0 { dst = newDownloadWriter(fd, resp.ContentLength) } - _, err = io.Copy(dst, resp.Body) - dst.Close() - if err != nil { + if _, err = io.Copy(dst, resp.Body); err != nil { + os.Remove(tmpfile) + return err + } + if err = dst.Close(); err != nil { os.Remove(tmpfile) return err }