Skip to content

Commit f6874b7

Browse files
committed
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.
1 parent 7666088 commit f6874b7

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

easybuild/tools/filetools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,9 @@ def verify_checksum(path, checksums, computed_checksums=None):
13051305
checksum = checksum[filename]
13061306
except KeyError:
13071307
raise EasyBuildError("Missing checksum for %s in %s", filename, checksum)
1308+
if not verify_checksum(path, checksum, computed_checksums):
1309+
return False
1310+
continue
13081311

13091312
if isinstance(checksum, str):
13101313
# if no checksum type is specified, it is assumed to be MD5 (32 characters) or SHA256 (64 characters)

test/framework/filetools.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ def test_checksums(self):
356356
# Check dictionary
357357
alt_checksums = (known_checksums['sha256'],)
358358
self.assertTrue(ft.verify_checksum(fp, {os.path.basename(fp): known_checksums['sha256']}))
359+
# None is accepted
360+
self.assertTrue(ft.verify_checksum(fp, {os.path.basename(fp): None}))
359361
faulty_dict = {'wrong-name': known_checksums['sha256']}
360362
self.assertErrorRegex(EasyBuildError,
361363
"Missing checksum for " + os.path.basename(fp) + " in .*wrong-name.*",
@@ -371,6 +373,8 @@ def test_checksums(self):
371373
self.assertTrue(ft.verify_checksum(fp, known_checksums['sha256']))
372374

373375
# Test dictionary-type checksums
376+
self.assertErrorRegex(EasyBuildError, "Missing checksum for", ft.verify_checksum,
377+
fp, {os.path.basename(fp): None})
374378
for checksum in [known_checksums[x] for x in ['sha256']]:
375379
dict_checksum = {os.path.basename(fp): checksum, 'foo': 'baa'}
376380
self.assertTrue(ft.verify_checksum(fp, dict_checksum))

0 commit comments

Comments
 (0)