glb_writer: restore writable mode before removing staging file on failure (GLB-WRITER-RO-CLEANUP) #719

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

@⁠kirigayakazima on GitHub · 2026-11-24 12:51 UTC · original
kirigayakazima:fix/glb-writer-ro-cleanup → main · +46 −0 · 2 files · 1 commits · open

Claimed in the coordination issue as: GLB-WRITER-RO-CLEANUP #14

What and why

In tools/glb_writer.py (_write_bytes_atomic), os.chmod(tmp_path, published_mode(out_path)) applies the destination file's mode to .glb-*.tmp before calling _replace(tmp_path, out_path). When publishing over a read-only (0o444) .glb fails on Windows (or _replace fails while the staging file carries 0o444), os.remove(tmp_path) in except BaseException: hits PermissionError ([WinError 5]), is swallowed by except OSError: pass, and leaves the orphaned .glb-*.tmp file behind.

Restores 0o600 on tmp_path before os.remove(tmp_path) in the cleanup block (guarded with except OSError: pass) and adds two synthetic regression tests in tests/test_glb_writer.py.

Tested

Windows 11 x64, Python 3.14.7, CPU only, synthetic bytes only (no game files). Commit bb27da204adb88f5d3c1178583f460dd7483c632.

  • python -I tests/test_glb_writer.py -v:
    • against main (21625bca) with the two new tests: both fail (AssertionError: ['.glb-*.tmp'] != []);
    • with the fix: 72 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/glb_writer.py tests/test_glb_writer.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:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/719) `kirigayakazima:fix/glb-writer-ro-cleanup` → `main` · +46 −0 · 2 files · 1 commits · open Claimed in the coordination issue as: GLB-WRITER-RO-CLEANUP https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 ### What and why In `tools/glb_writer.py` (`_write_bytes_atomic`), `os.chmod(tmp_path, published_mode(out_path))` applies the destination file's mode to `.glb-*.tmp` before calling `_replace(tmp_path, out_path)`. When publishing over a read-only (`0o444`) `.glb` fails on Windows (or `_replace` fails while the staging file carries `0o444`), `os.remove(tmp_path)` in `except BaseException:` hits `PermissionError` (`[WinError 5]`), is swallowed by `except OSError: pass`, and leaves the orphaned `.glb-*.tmp` file behind. Restores `0o600` on `tmp_path` before `os.remove(tmp_path)` in the cleanup block (guarded with `except OSError: pass`) and adds two synthetic regression tests in `tests/test_glb_writer.py`. ### Tested Windows 11 x64, Python 3.14.7, CPU only, synthetic bytes only (no game files). Commit `bb27da204adb88f5d3c1178583f460dd7483c632`. - `python -I tests/test_glb_writer.py -v`: - against `main` (`21625bca`) with the two new tests: both fail (`AssertionError: ['.glb-*.tmp'] != []`); - with the fix: **72 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/glb_writer.py tests/test_glb_writer.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:52 +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 writable mode before deleting staging file in tools/glb_writer.py.
  • Unit tests in tests/test_glb_writer.py PASS.
**@⁠abnalstlll-byte** on GitHub · 2026-11-24 13:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/719#pullrequestreview-6039982046) · **approved these changes** Audited and verified. Clean-room compliant. - Restores 0o600 writable mode before deleting staging file in tools/glb_writer.py. - Unit tests in tests/test_glb_writer.py PASS.
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 04:02 UTC · original · approved these changes

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

**@⁠tiguan26** on GitHub · 2026-11-25 04:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/719#pullrequestreview-6051686410) · **approved these changes** 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).
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/719/head:github-bot/gh-719'
git switch 'github-bot/gh-719'

Merge

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