shader_link_check: restore writable mode before unlinking staging file on failure (SHADER-LINK-CHECK-RO-CLEANUP) #715

Open
github-bot wants to merge 1 commit from github-bot/gh-715 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-24 12:49 UTC · original
kirigayakazima:fix/shader-link-check-ro-cleanup → main · +40 −1 · 2 files · 1 commits · open

Claimed in the coordination issue as: SHADER-LINK-CHECK-RO-CLEANUP #14

What and why

In tools/shader_link_check.py (write_report), os.chmod(temporary, published_mode(path)) copies a read-only (0o444) report's mode onto .shader-link-*.tmp before os.replace(temporary, path). When os.replace fails on Windows (including attempting to replace a read-only destination), finally: calls temporary.unlink(missing_ok=True) without restoring write permissions or catching OSError:

  1. On Windows, unlink raises a second PermissionError inside finally, masking the original os.replace exception (__context__).
  2. The .shader-link-*.tmp staging file is leaked in the output directory while the existing report stays intact.

This clears temporary = None after os.replace succeeds and restores 0o600 (with OSError guarded) before unlinking temporary in finally, adding two synthetic regression tests in tests/test_shader_link_check.py.

Tested

Windows 11 x64, Python 3.14.7, CPU only, synthetic inputs only (no game files). Commit 940b0ae227d694f1c96b046e325bc4d93f3030ee.

  • python -I tests/test_shader_link_check.py -v:
    • against main (21625bca) with the two new tests: both new tests fail (second PermissionError in finally masks the os.replace failure and leaves .shader-link-*.tmp);
    • with the fix: 52 tests, OK (0 skipped).
  • python -I tests/test_ci_registration.py: 15 tests, OK.
  • python -I tests/test_text_write_line_endings.py: 3 tests, OK.
  • python -I scripts/check_no_game_data.py tools/shader_link_check.py tests/test_shader_link_check.py, python -m compileall -q tools tests, git diff --check: clean (exit 0).

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)
**@⁠kirigayakazima** on GitHub · 2026-11-24 12:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/715) `kirigayakazima:fix/shader-link-check-ro-cleanup` → `main` · +40 −1 · 2 files · 1 commits · open Claimed in the coordination issue as: SHADER-LINK-CHECK-RO-CLEANUP https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 ### What and why In `tools/shader_link_check.py` (`write_report`), `os.chmod(temporary, published_mode(path))` copies a read-only (`0o444`) report's mode onto `.shader-link-*.tmp` before `os.replace(temporary, path)`. When `os.replace` fails on Windows (including attempting to replace a read-only destination), `finally:` calls `temporary.unlink(missing_ok=True)` without restoring write permissions or catching `OSError`: 1. On Windows, `unlink` raises a second `PermissionError` inside `finally`, masking the original `os.replace` exception (`__context__`). 2. The `.shader-link-*.tmp` staging file is leaked in the output directory while the existing report stays intact. This clears `temporary = None` after `os.replace` succeeds and restores `0o600` (with `OSError` guarded) before unlinking `temporary` in `finally`, adding two synthetic regression tests in `tests/test_shader_link_check.py`. ### Tested Windows 11 x64, Python 3.14.7, CPU only, synthetic inputs only (no game files). Commit `940b0ae227d694f1c96b046e325bc4d93f3030ee`. - `python -I tests/test_shader_link_check.py -v`: - against `main` (`21625bca`) with the two new tests: both new tests fail (second `PermissionError` in `finally` masks the `os.replace` failure and leaves `.shader-link-*.tmp`); - with the fix: **52 tests, OK** (0 skipped). - `python -I tests/test_ci_registration.py`: **15 tests, OK**. - `python -I tests/test_text_write_line_endings.py`: **3 tests, OK**. - `python -I scripts/check_no_game_data.py tools/shader_link_check.py tests/test_shader_link_check.py`, `python -m compileall -q tools tests`, `git diff --check`: clean (exit `0`). GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:17:42 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 13:25 UTC · original · approved these changes

Audited and verified. Clean-room compliant.

  • Restores 0o600 file mode before unlinking staging file on failure in tools/shader_link_check.py.
  • Regression tests in tests/test_shader_link_check.py PASS.
**@⁠abnalstlll-byte** on GitHub · 2026-11-24 13:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/715#pullrequestreview-6039985342) · **approved these changes** Audited and verified. Clean-room compliant. - Restores 0o600 file mode before unlinking staging file on failure in tools/shader_link_check.py. - Regression tests in tests/test_shader_link_check.py PASS.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/715/head:github-bot/gh-715'
git switch 'github-bot/gh-715'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-715'
git switch 'github-bot/gh-715'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-715'
git switch 'github-bot/gh-715'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-715'
git switch 'main'
git merge --squash 'github-bot/gh-715'
git switch 'main'
git merge --ff-only 'github-bot/gh-715'
git switch 'main'
git merge 'github-bot/gh-715'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.