Skip to content

Commit e628f15

Browse files
Wauplinclaude
andauthored
[Download] Probe umask next to incomplete file instead of two levels above destination (#4305)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f4a91c2 commit e628f15

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/huggingface_hub/file_download.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,8 +1907,12 @@ def _chmod_and_move(src: Path, dst: Path) -> None:
19071907
- Fix issue: https://github.com/huggingface/huggingface_hub/issues/1141
19081908
- Fix issue: https://github.com/huggingface/huggingface_hub/issues/1215
19091909
"""
1910-
# Get umask by creating a temporary file in the cached repo folder.
1911-
tmp_file = dst.parent.parent / f"tmp_{uuid.uuid4()}"
1910+
# Get umask by creating a temporary file in the folder containing the incomplete file.
1911+
# We know this folder is writable since the incomplete file has just been written there.
1912+
# Probing next to `dst` is not always possible: when downloading to a local dir, `dst` is the
1913+
# final file location and its parents might not be writable (e.g. read-only root filesystem).
1914+
# See https://github.com/huggingface/huggingface_hub/issues/4304.
1915+
tmp_file = src.parent / f"tmp_{uuid.uuid4()}"
19121916
try:
19131917
tmp_file.touch()
19141918
cache_dir_mode = Path(tmp_file).stat().st_mode

0 commit comments

Comments
 (0)