From 7157476ea9f0cb8e359a87b42c5da9b809881c90 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Mon, 2 Dec 2024 13:11:18 +0100 Subject: [PATCH] Allow nesting values in checksum dicts A checksum entry such as `{'file': value}` is now interpreted as-if it was just `value` if the `'file'` matches. This especially allows `None` values that currently lead to a type error. --- easybuild/tools/filetools.py | 3 +++ test/framework/filetools.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/easybuild/tools/filetools.py b/easybuild/tools/filetools.py index 4cace27090..d2f7b9d7fe 100644 --- a/easybuild/tools/filetools.py +++ b/easybuild/tools/filetools.py @@ -1305,6 +1305,9 @@ def verify_checksum(path, checksums, computed_checksums=None): checksum = checksum[filename] except KeyError: raise EasyBuildError("Missing checksum for %s in %s", filename, checksum) + if not verify_checksum(path, checksum, computed_checksums): + return False + continue if isinstance(checksum, str): # if no checksum type is specified, it is assumed to be MD5 (32 characters) or SHA256 (64 characters) diff --git a/test/framework/filetools.py b/test/framework/filetools.py index e59c3099f1..edf3a942c2 100644 --- a/test/framework/filetools.py +++ b/test/framework/filetools.py @@ -356,6 +356,8 @@ def test_checksums(self): # Check dictionary alt_checksums = (known_checksums['sha256'],) self.assertTrue(ft.verify_checksum(fp, {os.path.basename(fp): known_checksums['sha256']})) + # None is accepted + self.assertTrue(ft.verify_checksum(fp, {os.path.basename(fp): None})) faulty_dict = {'wrong-name': known_checksums['sha256']} self.assertErrorRegex(EasyBuildError, "Missing checksum for " + os.path.basename(fp) + " in .*wrong-name.*", @@ -371,6 +373,8 @@ def test_checksums(self): self.assertTrue(ft.verify_checksum(fp, known_checksums['sha256'])) # Test dictionary-type checksums + self.assertErrorRegex(EasyBuildError, "Missing checksum for", ft.verify_checksum, + fp, {os.path.basename(fp): None}) for checksum in [known_checksums[x] for x in ['sha256']]: dict_checksum = {os.path.basename(fp): checksum, 'foo': 'baa'} self.assertTrue(ft.verify_checksum(fp, dict_checksum))