Skip to content

Commit

Permalink
Merge pull request #717 from yuvipanda/cleanup-retrieve
Browse files Browse the repository at this point in the history
Don't open file twice when downloading conda
  • Loading branch information
yuvipanda authored Oct 19, 2021
2 parents 909b257 + de14669 commit d4be3c1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tljh/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ def download_miniconda_installer(installer_url, sha256sum):
of given version, verifies the sha256sum & provides path to it to the `with`
block to run.
"""
with tempfile.NamedTemporaryFile() as f:
with open(f.name, 'wb') as f:
f.write(requests.get(installer_url).content)
with tempfile.NamedTemporaryFile('wb') as f:
f.write(requests.get(installer_url).content)
# Remain in the NamedTemporaryFile context, but flush changes, see:
# https://docs.python.org/3/library/os.html#os.fsync
f.flush()
os.fsync(f.fileno())

if sha256_file(f.name) != sha256sum:
raise Exception('sha256sum hash mismatch! Downloaded file corrupted')
Expand Down

0 comments on commit d4be3c1

Please sign in to comment.