Let known_size checking of verify_hash be optional.
This commit is contained in:
parent
df9b829346
commit
1976ccb843
1 changed files with 12 additions and 1 deletions
|
@ -539,7 +539,13 @@ def normalize(text):
|
|||
'''
|
||||
return os.path.normpath(os.path.normcase(text))
|
||||
|
||||
def verify_hash(path, known_size, known_hash, callback=None):
|
||||
def verify_hash(
|
||||
path,
|
||||
known_hash,
|
||||
*,
|
||||
known_size=None,
|
||||
callback=None,
|
||||
):
|
||||
'''
|
||||
callback:
|
||||
A function that takes three parameters:
|
||||
|
@ -563,6 +569,11 @@ def verify_hash(path, known_size, known_hash, callback=None):
|
|||
if callback is not None:
|
||||
callback(path, checked_bytes, file_size)
|
||||
|
||||
if known_size is not None:
|
||||
file_size = os.path.getsize(path.absolute_path)
|
||||
if file_size != known_size:
|
||||
raise ValidationError(f'File size {file_size} != known size {known_size}.')
|
||||
|
||||
file_hash = hasher.hexdigest()
|
||||
if file_hash != known_hash:
|
||||
raise ValidationError(f'File hash "{file_hash}" != known hash "{known_hash}".')
|
||||
|
|
Loading…
Reference in a new issue