Catch exceptions if we can't read a file to generate a hash

This commit is contained in:
Greg Neagle
2020-01-13 22:24:31 -08:00
parent e7ffb40518
commit 3bd988ffdc

View File

@@ -40,15 +40,17 @@ def gethash(filename, hash_function):
"""
if not os.path.isfile(filename):
return 'NOT A FILE'
fileref = open(filename, 'rb')
while True:
chunk = fileref.read(2**16)
if not chunk:
break
hash_function.update(chunk)
fileref.close()
return hash_function.hexdigest()
try:
fileref = open(filename, 'rb')
while True:
chunk = fileref.read(2**16)
if not chunk:
break
hash_function.update(chunk)
fileref.close()
return hash_function.hexdigest()
except (OSError, IOError):
return 'HASH_ERROR'
def getmd5hash(filename):