Skip to content

Fix umask probe writing tmp file outside download dir#4305

Merged
Wauplin merged 1 commit into
mainfrom
fix-umask-probe-local-dir
Jun 3, 2026
Merged

Fix umask probe writing tmp file outside download dir#4305
Wauplin merged 1 commit into
mainfrom
fix-umask-probe-local-dir

Conversation

@Wauplin

@Wauplin Wauplin commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Fixes #4304 cc @quachc for reported it

When moving a finished download into place, _chmod_and_move probes the effective umask by touching a temporary tmp_<uuid> file at dst.parent.parent. That made sense for the cache layout (.../blobs/<etag> → two levels up is the repo folder), but since the local-dir download revamp (#2223) the same helper also receives dst = {local_dir}/<filename>. For a top-level file in --local-dir /data, two levels up is /, so we were touching /tmp_<uuid> at the filesystem root which fails with [Errno 30] Read-only file system on containers with a read-only root FS (and silently creates/deletes files at / on writable ones).

The fix probes next to the .incomplete file (src.parent) instead, which is guaranteed writable since we just wrote the download there: blobs/ in cache mode, {local_dir}/.cache/huggingface/download/ in local-dir mode. Same umask result, no more stray writes outside the download tree.

Quick check that the warning is gone with an unwritable destination parent:

from pathlib import Path
from huggingface_hub.file_download import _chmod_and_move
import tempfile, os
with tempfile.TemporaryDirectory() as d:
    src = Path(d) / 'sub' / 'file.incomplete'
    src.parent.mkdir()
    src.write_text('hello')
    _chmod_and_move(src, Path(d) / 'file.txt')
    print('moved without warning')

🤖 Generated with Claude Code


Note

Low Risk
Single-path change in download finalization with no API or security impact; reduces filesystem side effects.

Overview
Fixes _chmod_and_move so the umask probe no longer creates a temporary file two levels above the final destination.

When finishing a download, the library infers permissions by touching a zero-byte tmp_<uuid> file and reading its mode. That probe used dst.parent.parent, which matches the Hub cache layout (blobs/ → repo folder) but breaks for local_dir downloads where dst is the real file path (e.g. /data/model.bin → probe at /). On read-only root filesystems that triggers warnings and failed chmod; on writable systems it can litter the root with probe files.

The probe now runs in src.parent (next to the .incomplete file), which is always writable because the download just wrote there—cache blobs/ or local-dir .cache/huggingface/download/. Permission behavior is unchanged; only the probe location moves.

Reviewed by Cursor Bugbot for commit 26b3ac7. Bugbot is set up for automated code reviews on this repo. Configure here.

…above destination

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bot-ci-comment

bot-ci-comment Bot commented Jun 3, 2026

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Wauplin Wauplin marked this pull request as ready for review June 3, 2026 13:22
@Wauplin Wauplin changed the title [Download] Fix umask probe writing tmp file outside download dir Fix umask probe writing tmp file outside download dir Jun 3, 2026
@Wauplin

Wauplin commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator Author

As per #4304 (comment), bug is confirmed to be resolved, hence I'm merging this PR

@Wauplin Wauplin merged commit e628f15 into main Jun 3, 2026
26 checks passed
@Wauplin Wauplin deleted the fix-umask-probe-local-dir branch June 3, 2026 14:11
@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.18.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Errno 30] Read-only file system: '/tmp_<uuid>' when downloading to local folder

1 participant