rpf9_names: make the staging file deletable when a replace fails (RPF9-NAMES-STAGE-CLEANUP) #794

Merged
djrolfes merged 1 commit from upstream-pr/794 into main 2026-11-28 14:28:16 +00:00
djrolfes commented 2026-11-24 13:53:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by djrolfes on 2026-11-24T13:53:12Z.


Claimed in the coordination issue as: RPF9-NAMES-STAGE-CLEANUP (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133477447)

Depends on: none

Fixes: none (the work item is the finding pattern in issue #14; there is no separate issue to close)

Independent branch update

Head beb75ec56, based on e18b59a5b, contains exactly one topic commit. Removed the accidentally inherited #771 concurrency change and all sibling cleanup commits; this PR is now genuinely independent, so Depends on: none is accurate. Retested on Linux: 22 tests pass, Python compileall, changed-file scanner and diff checks pass. Clean merge-tree against 5da72d19f. Original head preserved; branch updated with an explicit lease. A passing label check is not full CI, and no hosted-suite pass is claimed. AI-assisted.

What and why

tools/rpf9_names.py's publish_report stages the JSON report in a TemporaryDirectory next to the destination and chmods the staged file to the destination's permission bits before os.replace. When the replace fails over a read-only report on Windows, the staged file is read-only, so the context-manager cleanup cannot delete it: the staging directory is stranded beside the report and the cleanup's PermissionError replaces the real error that main is supposed to turn into its named cannot write report diagnostic.

The cleanup now runs in a finally: make the staged file writable (0o600) before the directory is cleaned up and let one delete failure pass (suppress(OSError)), so the caller's except OSError still names the replace problem and exits 2. A successful publish is byte-for-byte unchanged, and a failed one leaves the prior report intact. The shape is the one navmesh_index.py, bvh_index.py and (in #789) story_index.py use.

Tested

  • python3 -I tests/test_rpf9_names.py: 22 tests OK, including the new test_failed_replace_of_read_only_report_makes_stage_deletable, which fails against the old code on the made-deletable assertion (it mocks the replace as failing over a 0o444 report, asserts the stage was made deletable, the prior report untouched, and no .rpf9_names- staging directory stranded).
  • python3 -m compileall -q tools/rpf9_names.py tests/test_rpf9_names.py clean; python3 -I scripts/check_no_game_data.py tools/rpf9_names.py tests/test_rpf9_names.py passes; synthetic archives only.

GPUs tested: n/a (standard-library tool; no game files, nothing online)

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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473468347 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/794). Originally posted by [djrolfes](https://github.com/djrolfes) on 2026-11-24T13:53:12Z. --- Claimed in the coordination issue as: RPF9-NAMES-STAGE-CLEANUP (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133477447) Depends on: none Fixes: none (the work item is the finding pattern in issue #14; there is no separate issue to close) ### Independent branch update Head `beb75ec56`, based on `e18b59a5b`, contains exactly one topic commit. Removed the accidentally inherited #771 concurrency change and all sibling cleanup commits; this PR is now genuinely independent, so `Depends on: none` is accurate. Retested on Linux: **22 tests pass**, Python compileall, changed-file scanner and diff checks pass. Clean merge-tree against `5da72d19f`. Original head preserved; branch updated with an explicit lease. A passing label check is not full CI, and no hosted-suite pass is claimed. AI-assisted. ### What and why `tools/rpf9_names.py`'s `publish_report` stages the JSON report in a `TemporaryDirectory` next to the destination and chmods the staged file to the destination's permission bits before `os.replace`. When the replace fails over a read-only report on Windows, the staged file is read-only, so the context-manager cleanup cannot delete it: the staging directory is stranded beside the report and the cleanup's `PermissionError` replaces the real error that `main` is supposed to turn into its named `cannot write report` diagnostic. The cleanup now runs in a `finally`: make the staged file writable (`0o600`) before the directory is cleaned up and let one delete failure pass (`suppress(OSError)`), so the caller's `except OSError` still names the replace problem and exits 2. A successful publish is byte-for-byte unchanged, and a failed one leaves the prior report intact. The shape is the one `navmesh_index.py`, `bvh_index.py` and (in #789) `story_index.py` use. ### Tested - `python3 -I tests/test_rpf9_names.py`: 22 tests OK, including the new `test_failed_replace_of_read_only_report_makes_stage_deletable`, which fails against the old code on the made-deletable assertion (it mocks the replace as failing over a `0o444` report, asserts the stage was made deletable, the prior report untouched, and no `.rpf9_names-` staging directory stranded). - `python3 -m compileall -q tools/rpf9_names.py tests/test_rpf9_names.py` clean; `python3 -I scripts/check_no_game_data.py tools/rpf9_names.py tests/test_rpf9_names.py` passes; synthetic archives only. GPUs tested: n/a (standard-library tool; no game files, nothing online) 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)
djrolfes commented 2026-11-25 19:45:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by djrolfes on 2026-11-25T19:45:36Z.


Rebuilt this branch independently on main e18b59a5b: beb75ec56, exactly one cleanup commit. Removed #771 and sibling cleanup commits rather than adding a false dependency. 22 focused tests, compileall, changed-file scan and diff checks pass; clean merge-tree against 5da72d19f. Explicit old-head lease used; prior head preserved. No full hosted CI result is inferred from a label check. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7172729328 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/794#issuecomment-7172729328). Originally posted by [djrolfes](https://github.com/djrolfes) on 2026-11-25T19:45:36Z. --- Rebuilt this branch independently on main e18b59a5b: beb75ec56, exactly one cleanup commit. Removed #771 and sibling cleanup commits rather than adding a false dependency. 22 focused tests, compileall, changed-file scan and diff checks pass; clean merge-tree against 5da72d19f. Explicit old-head lease used; prior head preserved. No full hosted CI result is inferred from a label check. AI-assisted.
MoonEyes commented 2026-11-28 14:28:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:28:12Z.


Red/green: classified READY by cloud-1 (red on main 09c153948, green on head merged with main); head beb75ec566 unchanged since 2026-11-25, before that run.
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7240693576 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/794#issuecomment-7240693576). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T14:28:12Z. --- Red/green: classified READY by cloud-1 (red on main 09c153948, green on head merged with main); head beb75ec56606 unchanged since 2026-11-25, before that run. Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
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!794
No description provided.