Skip to content

Commit

Permalink
Fixed same hasher object being reused between download retries in pyt…
Browse files Browse the repository at this point in the history
…hon build script.
  • Loading branch information
namark committed Feb 10, 2022
1 parent 80fe927 commit 056dfb9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions hifi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def executeSubprocess(processArgs, folder=None, env=None):
os.chdir(restoreDir)


def hashFile(file, hasher = hashlib.sha512()):
def hashFile(file, hasherType = hashlib.sha512):
hasher = hasherType()
with open(file, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hasher.update(chunk)
Expand All @@ -99,7 +100,7 @@ def hashFolder(folder):
filenames = recursiveFileList(folder)
return hashFiles(filenames)

def downloadFile(urls, hash=None, hasher=hashlib.sha512(), retries=3):
def downloadFile(urls, hash=None, hasher=hashlib.sha512, retries=3):
for url in urls:
for i in range(retries):
tempFileName = None
Expand Down Expand Up @@ -133,7 +134,7 @@ def downloadFile(urls, hash=None, hasher=hashlib.sha512(), retries=3):
raise RuntimeError("Failed to download file from any of {}".format(urls))


def downloadAndExtract(urls, destPath, hash=None, hasher=hashlib.sha512()):
def downloadAndExtract(urls, destPath, hash=None, hasher=hashlib.sha512):
tempFileName = downloadFile(urls, hash, hasher)
try:
with zipfile.ZipFile(tempFileName) as zip:
Expand Down

0 comments on commit 056dfb9

Please sign in to comment.