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

Open
opened 2026-11-26 20:18:57 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/719
Author: @kirigayakazima
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/glb-writer-ro-cleanup


📝 Commits (1)

  • bb27da2 glb_writer: restore writable mode before removing staging file on failure

📊 Changes

2 files changed (+46 additions, -0 deletions)

View changed files

📝 tests/test_glb_writer.py (+42 -0)
📝 tools/glb_writer.py (+4 -0)

📄 Description

Claimed in the coordination issue as: GLB-WRITER-RO-CLEANUP https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7131973085

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/719 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/glb-writer-ro-cleanup` --- ### 📝 Commits (1) - [`bb27da2`](https://github.com/ubiquitarianism/leonida/commit/bb27da204adb88f5d3c1178583f460dd7483c632) glb_writer: restore writable mode before removing staging file on failure ### 📊 Changes **2 files changed** (+46 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_glb_writer.py` (+42 -0) 📝 `tools/glb_writer.py` (+4 -0) </details> ### 📄 Description Claimed in the coordination issue as: GLB-WRITER-RO-CLEANUP https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7131973085 ### 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#758
No description provided.