Skip to content

Commit 3b2ca8c

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 9adcc1a commit 3b2ca8c

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

easybuild/tools/filetools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,9 @@ def verify_checksum(path, checksums, computed_checksums=None):
12761276
checksum = checksum[filename]
12771277
except KeyError:
12781278
raise EasyBuildError("Missing checksum for %s in %s", filename, checksum)
1279+
if not verify_checksum(path, checksum, computed_checksums):
1280+
return False
1281+
continue
12791282

12801283
if isinstance(checksum, string_type):
12811284
# 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
@@ -372,6 +372,8 @@ def test_checksums(self):
372372
# Check dictionary
373373
alt_checksums = (known_checksums['sha256'],)
374374
self.assertTrue(ft.verify_checksum(fp, {os.path.basename(fp): known_checksums['sha256']}))
375+
# None is accepted
376+
self.assertTrue(ft.verify_checksum(fp, {os.path.basename(fp): None}))
375377
faulty_dict = {'wrong-name': known_checksums['sha256']}
376378
self.assertErrorRegex(EasyBuildError,
377379
"Missing checksum for " + os.path.basename(fp) + " in .*wrong-name.*",
@@ -388,6 +390,8 @@ def test_checksums(self):
388390
self.assertTrue(ft.verify_checksum(fp, known_checksums['sha256']))
389391

390392
# Test dictionary-type checksums
393+
self.assertErrorRegex(EasyBuildError, "Missing checksum for", ft.verify_checksum,
394+
fp, {os.path.basename(fp): None})
391395
for checksum in [known_checksums[x] for x in ('md5', 'sha256')]:
392396
dict_checksum = {os.path.basename(fp): checksum, 'foo': 'baa'}
393397
self.assertTrue(ft.verify_checksum(fp, dict_checksum))

0 commit comments

Comments
 (0)