Skip to content

Commit

Permalink
Allow nesting values in checksum dicts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Flamefire committed Dec 2, 2024
1 parent 9adcc1a commit 3b2ca8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,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, string_type):
# if no checksum type is specified, it is assumed to be MD5 (32 characters) or SHA256 (64 characters)
Expand Down
4 changes: 4 additions & 0 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,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.*",
Expand All @@ -388,6 +390,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 ('md5', 'sha256')]:
dict_checksum = {os.path.basename(fp): checksum, 'foo': 'baa'}
self.assertTrue(ft.verify_checksum(fp, dict_checksum))
Expand Down

0 comments on commit 3b2ca8c

Please sign in to comment.