Skip to content

Commit 132b0c2

Browse files
committed
Truncate downloaded file after checksum mismatch
This enables proper recovery in a next attempt.
1 parent 3df22e2 commit 132b0c2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- Truncate downloaded file if checksums mismatch. This allows graceful recovery on a retry
12+
instead of having to restart the entire process.
13+
914
## [0.0.1] - 2023-12-27
1015

1116
### Added

lib/patcher/download.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,14 @@ func (d *Downloader) doDownloadFile(
380380

381381
actualChecksum := observer.getChecksum()
382382
if !HashEqual(expectedChecksum, actualChecksum) {
383-
return offset,
384-
fmt.Errorf("downloaded file has invalid checksum for '%s' downloaded to '%s', expected %s, got %s",
383+
if err := file.Truncate(0); err != nil {
384+
return 0, fmt.Errorf("failed to truncate '%s' (because of checksum mismatch): %w", filename, err)
385+
}
386+
observer.resetChecksum()
387+
return 0,
388+
fmt.Errorf(
389+
"downloaded file has invalid checksum for '%s' downloaded to '%s', expected %s, got %s, "+
390+
"redownloading on the next attempt",
385391
downloadUrl, filename, expectedChecksum, actualChecksum)
386392
}
387393
return offset, nil

0 commit comments

Comments
 (0)