Skip to content

Commit d30853b

Browse files
d8ahazardWauplin
andauthored
Don't write the ref file unless necessary (#2657)
* Don't write the ref file unless necessary * Add exception handling when dealing with ref file * Update src/huggingface_hub/_snapshot_download.py Co-authored-by: Lucain <lucainp@gmail.com> * Update src/huggingface_hub/_snapshot_download.py --------- Co-authored-by: Lucain <lucainp@gmail.com> Co-authored-by: Lucain <lucain@huggingface.co>
1 parent 9e7ff04 commit d30853b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/huggingface_hub/_snapshot_download.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,12 @@ def snapshot_download(
256256
# In that case store a ref.
257257
if revision != commit_hash:
258258
ref_path = os.path.join(storage_folder, "refs", revision)
259-
os.makedirs(os.path.dirname(ref_path), exist_ok=True)
260-
with open(ref_path, "w") as f:
261-
f.write(commit_hash)
259+
try:
260+
os.makedirs(os.path.dirname(ref_path), exist_ok=True)
261+
with open(ref_path, "w") as f:
262+
f.write(commit_hash)
263+
except OSError as e:
264+
logger.warning(f"Ignored error while writing commit hash to {ref_path}: {e}.")
262265

263266
# we pass the commit_hash to hf_hub_download
264267
# so no network call happens if we already

0 commit comments

Comments
 (0)