shader_link_check: restore write mode before unlink on replace failure (SHADER-LINK-CHECK-STAGE-CLEANUP) #807

Closed
trigger337 wants to merge 1 commit from upstream-pr/807 into main
trigger337 commented 2026-11-24 14:02:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T14:02:32Z.


In tools/shader_link_check.py, write_report creates a temporary file and applies published_mode(path) before os.replace. If the target is read-only (e.g. 0o444), temporary.unlink in the finally block fails on Windows with PermissionError (WinError 5) if os.replace fails, leaving the temporary file behind.

Align with the repository standard:

  1. In finally, restore write permissions (try: os.chmod(temporary, 0o600); except OSError: pass) before calling unlink.
  2. Add synthetic regression test verifying PermissionError handling and cleanup on replace failure.

Tests pass (51/51 in test_shader_link_check.py), scripts/check_no_game_data.py passes cleanly.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473628379 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/807). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T14:02:32Z. --- In `tools/shader_link_check.py`, `write_report` creates a temporary file and applies `published_mode(path)` before `os.replace`. If the target is read-only (e.g. 0o444), `temporary.unlink` in the `finally` block fails on Windows with `PermissionError` (WinError 5) if `os.replace` fails, leaving the temporary file behind. Align with the repository standard: 1. In `finally`, restore write permissions (`try: os.chmod(temporary, 0o600); except OSError: pass`) before calling `unlink`. 2. Add synthetic regression test verifying `PermissionError` handling and cleanup on replace failure. Tests pass (51/51 in `test_shader_link_check.py`), `scripts/check_no_game_data.py` passes cleanly. agent: yes AI-assisted: yes
tiguan26 commented 2026-11-25 03:59:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T03:59:08Z.

Review: APPROVED


Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). Same pattern as the rest of the *-STAGE-CLEANUP series: on a failed replace the staged file gets 0o600 back before os.unlink, so a staged copy left read-only (the published mode on Windows) is still removed. Only the staging/permission lines change.

AI-assisted (Claude).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6051661929 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/807#pullrequestreview-6051661929). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T03:59:08Z. **Review:** APPROVED --- Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). Same pattern as the rest of the *-STAGE-CLEANUP series: on a failed replace the staged file gets 0o600 back before os.unlink, so a staged copy left read-only (the published mode on Windows) is still removed. Only the staging/permission lines change. AI-assisted (Claude).
PierreEbele commented 2026-11-25 20:57:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T20:57:39Z.


Reviewed 0f53b3e: write_report restores 0o600 on the staging file before unlink, so a failed replace cannot strand a read-only .shader-link-*.tmp on Windows; same _publish idiom as bvh_index/navmesh_index. Runs on Linux: 51 tests pass on the PR tree; on main with this test file only the new test fails (leftover staging file). Probes: success paths identical on both trees (published 0o444 mode preserved, no leftovers); under simulated Windows unlink denial main leaks the staging file and masks the replace error while the PR cleans up and surfaces the original error - the trigger is Windows-only and was verified on Linux via simulation. No findings. AI-assisted review.

Recommendation: Merge

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7174421547 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/807#issuecomment-7174421547). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T20:57:39Z. --- Reviewed 0f53b3e: `write_report` restores 0o600 on the staging file before unlink, so a failed replace cannot strand a read-only `.shader-link-*.tmp` on Windows; same `_publish` idiom as bvh_index/navmesh_index. Runs on Linux: 51 tests pass on the PR tree; on main with this test file only the new test fails (leftover staging file). Probes: success paths identical on both trees (published 0o444 mode preserved, no leftovers); under simulated Windows unlink denial main leaks the staging file and masks the replace error while the PR cleans up and surfaces the original error - the trigger is Windows-only and was verified on Linux via simulation. No findings. AI-assisted review. **Recommendation:** Merge
DadaCap commented 2026-11-28 11:33:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:33:20Z.


Thanks for the fix! We're closing this as a duplicate of #715, which makes the same change to write_report in tools/shader_link_check.py (making the staging file writable before deleting it after a failed replace) and also keeps the original replace error from being hidden by a failed delete. If this looks like a mistake, mention @DadaCap here at any time.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238629058 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/807#issuecomment-7238629058). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:33:20Z. --- Thanks for the fix! We're closing this as a duplicate of #715, which makes the same change to `write_report` in `tools/shader_link_check.py` (making the staging file writable before deleting it after a failed replace) and also keeps the original replace error from being hidden by a failed delete. If this looks like a mistake, mention @DadaCap here at any time. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!807
No description provided.