From 3bd988ffdca24044a76da3573db50cd22bf36014 Mon Sep 17 00:00:00 2001 From: Greg Neagle Date: Mon, 13 Jan 2020 22:24:31 -0800 Subject: [PATCH] Catch exceptions if we can't read a file to generate a hash --- code/client/munkilib/munkihash.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/code/client/munkilib/munkihash.py b/code/client/munkilib/munkihash.py index 374cd6ca..49914624 100644 --- a/code/client/munkilib/munkihash.py +++ b/code/client/munkilib/munkihash.py @@ -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):