Skip to content

Commit

Permalink
Use dst dir for temp file (pytorch#23629)
Browse files Browse the repository at this point in the history
Summary:
Fixes pytorch#23607
Pull Request resolved: pytorch#23629

Differential Revision: D16594223

Pulled By: soumith

fbshipit-source-id: db0275415111f08fc13ab6be00b76737a20f92df
  • Loading branch information
Ailing Zhang authored and facebook-github-bot committed Aug 1, 2019
1 parent 0ce950d commit 0a12ff7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion torch/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,12 @@ def _download_url_to_file(url, dst, hash_prefix, progress):
if content_length is not None and len(content_length) > 0:
file_size = int(content_length[0])

f = tempfile.NamedTemporaryFile(delete=False)
# We deliberately save it in a temp file and move it after
# download is complete. This prevents a local working checkpoint
# being overriden by a broken download.
dst_dir = os.path.dirname(dst)
f = tempfile.NamedTemporaryFile(delete=False, dir=dst_dir)

try:
if hash_prefix is not None:
sha256 = hashlib.sha256()
Expand Down

0 comments on commit 0a12ff7

Please sign in to comment.