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

Closed
leonida/mandy
trigger337 wants to merge 0 commits from fix/shader-link-check-stage-cleanup into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

trigger337 commented 2026-11-24 14:02:32 +00:00

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

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 approved these changes 2026-11-25 03:59:08 +00:00
tiguan26 left a comment

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).

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

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

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

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.

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.
Sign in to join this conversation.
No description provided.