calibrated_texture: atomic no-clobber export with MoveFileExW and cleanup (CALIBRATED-TEXTURE-NO-CLOBBER) #570
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!570
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/570/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Managilvosh on GitHub · 2026-11-24 08:34 UTC · original
Managilvosh:fix-calibrated-texture-no-clobber→main· +153 −5 · 2 files · 1 commits · merged 2026-11-25 19:47 UTCClaimed in the coordination issue as: #14
Summary
Resolves a Windows-specific failure in
tools/calibrated_texture.py:export_file()where unprivileged executions failed withPermissionError: [WinError 5] Access is deniedduring atomic texture export (force=False) becauseos.link(tmp, target)requires hardlink creation rights or specific local filesystem configurations not available to standard user accounts.Technical Implementation
force=False): Introduced_rename_no_clobber()wrappingos.rename(src, dst). On Windows,os.rename()calls Win32MoveFileExW(src, dst, 0)withoutMOVEFILE_REPLACE_EXISTING, which is an atomic filesystem operation that raisesFileExistsError([WinError 183]) ifdstexists while permitting standard unprivileged rename operations.os.link(src, dst)followed bytmp.unlink()infinally:. Ifos.linkraises any error (FileExistsErrororPermissionError), it fails safely by re-raising immediately without non-atomic existence checks or fallback replacement, eliminating any potential TOCTOU race.force=True): Upgraded replacement from bareos.replace()toreplace_retry.replace(), making overwrite exports resilient against transient background file locks.replace_retryretry loop with exponential backoff (FIRST_DELAY = 0.01s,MAX_DELAY = 0.25s,RETRY_SECONDS = 5.0s) for_rename_no_clobber(), retrying transient Windows error codes (WinError 5 and 32) while propagating non-transient errors immediately.with f:to guarantee handle closure before rename or unlinking. Temporary files are guaranteed to be cleaned up viafinally: tmp.unlink(missing_ok=True).Tested
python -m compileall -q tools/calibrated_texture.py tests/test_calibrated_texture_extra.py(PASS, exit code 0)python -I scripts/check_no_game_data.py tools/calibrated_texture.py tests/test_calibrated_texture_extra.py(PASS, 0 violations)python -I tests/test_calibrated_texture_extra.py(30/30 tests PASS, exit code 0; previously failed 2 tests with WinError 5)python -I tests/test_calibrated_texture.py(2 tests, PASS, 1 skipped)python -I tests/test_ttpf_assets.py(31 tests, PASS, 3 skipped)python -I tests/test_ttpf_mips.py(93 tests, PASS)AI-assisted: Yes (Google DeepMind Antigravity).
@PierreEbele on GitHub · 2026-11-25 00:41 UTC · original
Reviewed
f8650dc5: ran tests/test_calibrated_texture_extra.py (30 OK) and tests/test_calibrated_texture.py in the sandboxon this branch, and the same test file on main - 4 of the 5 new tests fail there, so they pin the fix (the concurrent-
destination one also passes on main, as os.link already had that property on POSIX). Ran a probe on both trees: the
existing target survives reject byte-for-byte, every failure path cleans the temp file, the TOCTOU race is rejected
through real os.link and a simulated no-clobber Windows rename, the retry is bounded by
seconds, non-transient errorsraise on attempt one. No findings; the Windows os.rename contract rests on CPython's docs (nothing here runs Windows).
AI-assisted review.
Recommendation: Merge
@aslan2142 on GitHub · 2026-11-25 19:47 UTC · original
Merged, thanks! The new test fails on
mainand passes with this.mainc606788bc+f8650dc5a: the semantic suite passes (491 files, 6,312 tests, 0 files failed);test_calibrated_texture_extrapass; the 15 docs and writer tests pass;check_no_game_data.pyis clean on the 2 changed files.AI-assisted (Claude Code, Claude Opus 5.5).