Skip to content

Commit

Permalink
Merge pull request easybuilders#4711 from Flamefire/non-dict
Browse files Browse the repository at this point in the history
Allow nesting values in checksum dicts
  • Loading branch information
bartoldeman authored Jan 13, 2025
2 parents 7d2dc3a + 7157476 commit 3e28cb6
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 @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.*",
Expand All @@ -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))
Expand Down

0 comments on commit 3e28cb6

Please sign in to comment.