mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:35:52 +01:00
[PR #570] [MERGED] calibrated_texture: atomic no-clobber export with MoveFileExW and cleanup (CALIBRATED-TEXTURE-NO-CLOBBER) #614
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#614
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/570
Author: @Managilvosh
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142
Base:
main← Head:fix-calibrated-texture-no-clobber📝 Commits (1)
f8650dccalibrated_texture: atomic no-clobber export with MoveFileExW and cleanup (CALIBRATED-TEXTURE-NO-CLOBBER)📊 Changes
2 files changed (+153 additions, -5 deletions)
View changed files
📝
tests/test_calibrated_texture_extra.py(+119 -0)📝
tools/calibrated_texture.py(+34 -5)📄 Description
Claimed in the coordination issue as: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7125764622
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).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.