Merge pull request #170 from ophiry/md5_handle_missing_file

return empty md5 if file doesnt exist
This commit is contained in:
Ruslan Kuprieiev
2017-08-15 01:08:28 +03:00
committed by GitHub
+8 -5
View File
@@ -46,11 +46,14 @@ def create_cb(name):
def file_md5(fname):
""" get the (md5 hexdigest, md5 digest) of a file """
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(1024*1000), b""):
hash_md5.update(chunk)
return (hash_md5.hexdigest(), hash_md5.digest())
if os.path.exists(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(1024*1000), b""):
hash_md5.update(chunk)
return (hash_md5.hexdigest(), hash_md5.digest())
else:
return (None, None)
class DataCloudBase(object):