mirror of
https://github.com/munki/munki.git
synced 2026-01-05 14:10:00 -06:00
Catch exceptions if we can't read a file to generate a hash
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user