Repository navigation
Fix Windows crash when downloading into a deep local_dir - #4546
Merged
Wauplin merged 2 commits intoJul 20, 2026
Merged
Conversation
get_local_download_paths / get_local_upload_paths apply the extended-length "\?\" prefix to the download/upload paths, but _huggingface_dir() created <local_dir>/.cache/huggingface with a plain mkdir first. For a deep local_dir that folder exceeds the Windows ~255 char limit, so the mkdir raised FileNotFoundError (WinError 206) before the prefix workaround ran. Apply the same prefix inside _huggingface_dir for its directory creation and bookkeeping files (CACHEDIR.TAG, .gitignore); the un-prefixed path is still returned so callers keep prefixing as before. Adds a Windows regression test covering a long local_dir (the existing test only covers a long filename).
Plain CreateDirectory fails once the directory path exceeds 247 characters (MAX_PATH minus room for an 8.3 file name), not 255: verified empirically that mkdir fails with WinError 206 from 248 onwards while file creation only fails at 260. Guard _huggingface_dir at >247 accordingly and cover both boundary windows (252 and 300) in the regression test.
askalf
marked this pull request as ready for review
July 19, 2026 15:40
|
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
approved these changes
Jul 20, 2026
Wauplin
left a comment
Collaborator
There was a problem hiding this comment.
Looks good! Thanks for reporting and fixing it :)
Collaborator
|
This PR has been shipped as part of the v1.25.0 release. |
This was referenced Sep 13, 2026
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.
On Windows the default is LongPathsEnabled=0, downloading into a deep local directory crash while creating the. cache/huggingface directory. That guard prefixes paths above 255 chars, but directory creation already fails at ≥248
(MAX_PATH minus 12 for legacy 8.3 names), so the 248-255 window slips through and throws.
The repro is local_dir whose absolute path lands in that 248-255 window + an ordinary file name -> the crash. The fix
is to lower the guard threshold to >247 so \?\ extended-length prefix applies across the whole failing range.
Testing is a parametrized regression test at [252, 300] chars, guarded to windows, then executing in your windows-latest CI matrix. AI assisted me with this PR, I've reviewed the change and understand every line.
Note
Low Risk
Scoped to Windows filesystem path handling in local-dir cache setup; behavior elsewhere is unchanged and covered by a targeted regression test.
Overview
Fixes WinError 206 when downloading into a very deep
local_diron Windows without long-path support enabled._huggingface_dirnow applies the\\?\extended-length prefix formkdir,CACHEDIR.TAG, and.gitignorewhen the absolute.cache/huggingfacepath exceeds 247 characters (directory limit before the existing 255-char guard on download/upload paths). It still returns the normal unprefixed path so downstream path logic is unchanged.Adds a Windows-only parametrized test (
252and300char cache paths) that exercisesget_local_download_pathswith a longlocal_dir, not just a long filename.Reviewed by Cursor Bugbot for commit 02efc97. Bugbot is set up for automated code reviews on this repo. Configure here.