Commit 4785dfac authored by Philip Meier's avatar Philip Meier Committed by Soumith Chintala
Browse files

Fix logic error in check_integrity (#871)

* fixed check integrity

* stylistic changes

* flake8
parent 90091b5b
...@@ -17,20 +17,25 @@ def gen_bar_updater(): ...@@ -17,20 +17,25 @@ def gen_bar_updater():
return bar_update return bar_update
def calculate_md5(fpath, chunk_size=1024 * 1024):
md5 = hashlib.md5()
with open(fpath, 'rb') as f:
for chunk in iter(lambda: f.read(chunk_size), b''):
md5.update(chunk)
return md5.hexdigest()
def check_md5(fpath, md5, **kwargs):
return md5 == calculate_md5(fpath, **kwargs)
def check_integrity(fpath, md5=None): def check_integrity(fpath, md5=None):
if md5 is None:
return True
if not os.path.isfile(fpath): if not os.path.isfile(fpath):
return False return False
md5o = hashlib.md5() if md5 is None:
with open(fpath, 'rb') as f: return True
# read in 1MB chunks else:
for chunk in iter(lambda: f.read(1024 * 1024), b''): return check_md5(fpath, md5)
md5o.update(chunk)
md5c = md5o.hexdigest()
if md5c != md5:
return False
return True
def makedir_exist_ok(dirpath): def makedir_exist_ok(dirpath):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment