From afe1779ef7be57a76358cfb2de042c9b92c3ef76 Mon Sep 17 00:00:00 2001 From: Yao Ge Date: Mon, 4 May 2026 10:03:23 +0800 Subject: [PATCH] stackage: require sha1 or sha256 checksum, skip entries with neither Some GHC entries in upstream stack-setup-2.yaml (freebsd64-ino64 platform, versions 9.8.1 through 9.12.2) only provide sha256 without sha1. Previously the script hardcoded sha1 access, causing KeyError. - download() now accepts optional sha256, falls back to sha-256 checksum - load_stack_setup() explicitly selects sha1 or sha256; entries with neither checksum are skipped with a warning --- stackage.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/stackage.py b/stackage.py index 86353b8..3f7bb19 100755 --- a/stackage.py +++ b/stackage.py @@ -17,7 +17,7 @@ class StackageSession(object): def __init__(self): self._base_path = pathlib.Path(os.environ['TUNASYNC_WORKING_DIR']) - def download(self, dir_, url, sha1=None, force=False): + def download(self, dir_, url, sha1=None, sha256=None, force=False): dir_path = self._base_path / dir_ file_path = dir_path / url.split('/')[-1] if force and file_path.is_file(): @@ -32,6 +32,8 @@ def download(self, dir_, url, sha1=None, force=False): ] if sha1: args.append('--checksum=sha-1={}'.format(sha1)) + elif sha256: + args.append('--checksum=sha-256={}'.format(sha256)) subprocess.run(args, check=True) shutil.move('{}.tmp'.format(file_path), file_path) print('Downloaded {} to {}'.format(url, file_path), flush=True) @@ -45,10 +47,27 @@ def load_stack_setup(self): ) for platform in d['ghc']: for ver in d['ghc'][platform]: + meta = d['ghc'][platform][ver] + checksum_algo = None + checksum_value = None + if 'sha1' in meta: + checksum_algo = 'sha-1' + checksum_value = meta['sha1'] + elif 'sha256' in meta: + checksum_algo = 'sha-256' + checksum_value = meta['sha256'] + else: + print( + 'WARNING: no checksum for GHC {}/{} ({}), skipping' + .format(platform, ver, meta.get('url', '?')), + flush=True, + ) + continue self.download( 'ghc', - d['ghc'][platform][ver]['url'], - d['ghc'][platform][ver]['sha1'], + meta['url'], + sha1=checksum_value if checksum_algo == 'sha-1' else None, + sha256=checksum_value if checksum_algo == 'sha-256' else None, ) d['ghc'][platform][ver]['url'] = ( '{}/ghc/{}'