Fix umask probe writing tmp file outside download dir#4305
Merged
Conversation
…above destination Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
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. |
Collaborator
Author
|
As per #4304 (comment), bug is confirmed to be resolved, hence I'm merging this PR |
Contributor
|
This PR has been shipped as part of the v1.18.0 release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4304 cc @quachc for reported it
When moving a finished download into place,
_chmod_and_moveprobes the effective umask by touching a temporarytmp_<uuid>file atdst.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 receivesdst = {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 systemon containers with a read-only root FS (and silently creates/deletes files at/on writable ones).The fix probes next to the
.incompletefile (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:
🤖 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_moveso 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 useddst.parent.parent, which matches the Hub cache layout (blobs/→ repo folder) but breaks forlocal_dirdownloads wheredstis 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.incompletefile), which is always writable because the download just wrote there—cacheblobs/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.