Commit b9c14d9
[Download] Write cache ref file atomically in
`snapshot_download` rewrote `refs/<revision>` with a plain `open(path, "w")` on every
call, even when the commit hash was unchanged. `open(..., "w")` truncates the file
before rewriting it, so a concurrent reader can observe an empty revision and conclude
that a fully cached file is missing.
Use the existing `_cache_commit_hash_for_specific_revision` helper instead: it skips the
write when the ref is already up to date and otherwise writes to a temporary file and
`os.replace`s it into place. `hf_hub_download` and `HfApi.resolve_revision` already go
through it.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>snapshot_download (#4829)1 parent 8934ec0 commit b9c14d9
1 file changed
Lines changed: 14 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
22 | 28 | | |
23 | 29 | | |
24 | 30 | | |
| |||
412 | 418 | | |
413 | 419 | | |
414 | 420 | | |
415 | | - | |
416 | | - | |
| 421 | + | |
417 | 422 | | |
418 | | - | |
419 | | - | |
420 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
421 | 426 | | |
422 | | - | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
423 | 430 | | |
424 | 431 | | |
425 | 432 | | |
| |||
0 commit comments