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 <j-wasinger@hotmail.com>
This commit is contained in:
Rahman 2026-05-06 07:02:03 -06:00 committed by GitHub
parent aaa2b66285
commit b92c86deb7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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