From 522c69e95137d6839e394cefddd61004dd0c2e99 Mon Sep 17 00:00:00 2001 From: Wellington Dias Date: Sat, 31 Oct 2026 12:40:55 -0300 Subject: [PATCH] Download a cached release file again when its hash no longer matches its pin, in the same run, instead of stopping. --- tools/make_release.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/tools/make_release.py b/tools/make_release.py index cdd74985..c20d96b9 100644 --- a/tools/make_release.py +++ b/tools/make_release.py @@ -125,26 +125,30 @@ def fetch(name): path = DL / Path(url.split('?')[0]).name.replace('%7E', '~') if name == 'libvpx-src': path = DL / 'libvpx-1.17.0.tar.gz' - if not path.is_file(): - # into .part, renamed once complete: a cut connection leaves a .part that the next run resumes, never a - # short file under the final name - part = path.with_name(path.name + '.part') - have = part.stat().st_size if part.is_file() else 0 - print(f'download {url}' + (f' (resuming at {have} bytes)' if have else '')) - req = urllib.request.Request(url, headers={'Range': f'bytes={have}-'} if have else {}) - try: - with urllib.request.urlopen(req) as r: - if have and r.status != 206: # the server ignored the range: start over - have = 0 - with open(part, 'ab' if have else 'wb') as f: - shutil.copyfileobj(r, f) - except urllib.error.HTTPError as e: - if e.code != 416: # 416: the .part already holds the whole file - raise - part.replace(path) + if path.is_file(): + if sha256_file(path) == want: + return path + print(f'{path}: not the pinned file (a cut download or an older pin); downloading it again') + path.unlink() + # into .part, renamed once complete: a cut connection leaves a .part that the next run resumes, never a + # short file under the final name + part = path.with_name(path.name + '.part') + have = part.stat().st_size if part.is_file() else 0 + print(f'download {url}' + (f' (resuming at {have} bytes)' if have else '')) + req = urllib.request.Request(url, headers={'Range': f'bytes={have}-'} if have else {}) + try: + with urllib.request.urlopen(req) as r: + if have and r.status != 206: # the server ignored the range: start over + have = 0 + with open(part, 'ab' if have else 'wb') as f: + shutil.copyfileobj(r, f) + except urllib.error.HTTPError as e: + if e.code != 416: # 416: the .part already holds the whole file + raise + part.replace(path) got = sha256_file(path) if got != want: - path.unlink() # so the next run downloads it again instead of failing on the same file + path.unlink() # a .part resumed from another upload, or the URL now serves another file: start clean next run sys.exit(f'{path}: sha256 {got}, pinned {want}; deleted, run again to download it anew') return path