anim_move: restore write mode before unlink on replace failure and publish mode on Windows (ANIM-MOVE-STAGE-CLEANUP) #777

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

@⁠trigger337 on GitHub · 2026-11-24 13:42 UTC · original
trigger337:fix/anim-move-stage-cleanup → main · +40 −2 · 2 files · 1 commits · open

In tools/anim_move.py, _write_json_atomic creates a temporary file and previously skipped applying published_mode on Windows because os.unlink in the finally block fails with PermissionError (WinError 5) if replace_retry fails on read-only destinations.

Align with the repository standard:

  1. In finally, restore write permissions (try: os.chmod(staged.name, 0o600); except OSError: pass) before unlinking.
  2. Apply published_mode(destination) unconditionally so Windows outputs receive proper permissions instead of keeping NamedTemporaryFile's default 0o600 mode.
  3. Add synthetic regression tests verifying PermissionError handling and Windows published_mode application.

Tests pass (12/12 in test_anim_move.py), scripts/check_no_game_data.py passes cleanly.

agent: yes
AI-assisted: yes

**@⁠trigger337** on GitHub · 2026-11-24 13:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/777) `trigger337:fix/anim-move-stage-cleanup` → `main` · +40 −2 · 2 files · 1 commits · open In `tools/anim_move.py`, `_write_json_atomic` creates a temporary file and previously skipped applying `published_mode` on Windows because `os.unlink` in the `finally` block fails with `PermissionError` (WinError 5) if `replace_retry` fails on read-only destinations. Align with the repository standard: 1. In `finally`, restore write permissions (`try: os.chmod(staged.name, 0o600); except OSError: pass`) before unlinking. 2. Apply `published_mode(destination)` unconditionally so Windows outputs receive proper permissions instead of keeping `NamedTemporaryFile`'s default `0o600` mode. 3. Add synthetic regression tests verifying `PermissionError` handling and Windows `published_mode` application. Tests pass (12/12 in `test_anim_move.py`), `scripts/check_no_game_data.py` passes cleanly. agent: yes AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:20:56 +00:00
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 04:01 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; and the published mode now also applies on Windows (the os.name guard is gone), using file_mode.published_mode. Only the staging/permission lines change.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 04:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/777#pullrequestreview-6051679294) · **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; and the published mode now also applies on Windows (the os.name guard is gone), using file_mode.published_mode. Only the staging/permission lines change. AI-assisted (Claude).
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 20:05 UTC · original

Reviewed efe0568: I ran python3 -I tests/test_anim_move.py on Linux (12/12 on the PR; on main with this PR's test file only the os.name="nt" mode test fails), check_no_game_data.py (clean), and a probe against origin/main. The cleanup change is correct where reachable: with writable destination + published_mode forced to 0o444 + failing replace, main strands a read-only staged file and masks the replace error, this branch removes it and re-raises. But test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly never reaches that code as a normal user - the 0o444 destination raises at the pre-stage os.open(destination, os.O_WRONLY) check (line 589) before staging, so it also passes on main with the fix reverted (probe: staged file created: False on both trees). Please force published_mode on a writable destination (or patch the check) so the test fails on main, and assert the published mode in the os.name="nt" test rather than len(chmod_calls) > 0, which the new finally: chmod on the renamed-away staged name also satisfies. No product regression found. AI-assisted review.

Recommendation: Fix first

**@⁠PierreEbele** on GitHub · 2026-11-25 20:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/777#issuecomment-7173171616) Reviewed efe0568: I ran `python3 -I tests/test_anim_move.py` on Linux (12/12 on the PR; on main with this PR's test file only the os.name="nt" mode test fails), `check_no_game_data.py` (clean), and a probe against `origin/main`. The cleanup change is correct where reachable: with writable destination + `published_mode` forced to 0o444 + failing replace, main strands a read-only staged file and masks the replace error, this branch removes it and re-raises. But `test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly` never reaches that code as a normal user - the 0o444 destination raises at the pre-stage `os.open(destination, os.O_WRONLY)` check (line 589) before staging, so it also passes on main with the fix reverted (probe: `staged file created: False` on both trees). Please force `published_mode` on a writable destination (or patch the check) so the test fails on main, and assert the published mode in the os.name="nt" test rather than `len(chmod_calls) > 0`, which the new `finally:` chmod on the renamed-away staged name also satisfies. No product regression found. AI-assisted review. **Recommendation:** Fix first
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-26 06:57 UTC · original

Confirming @⁠PierreEbele's finding, and why my approval missed it. I ran the PR's test file against main's tool, and the cleanup test (..._replace_fails_even_if_readonly) did fail there. But this workspace runs as root, and root opens a 0o444 file for writing anyway, so it gets past the pre-stage os.open(destination, os.O_WRONLY) check and into the staged-file cleanup. As a normal user on Linux, and on Windows where the read-only attribute is honoured, that check refuses the destination before anything is staged, so the test passes on main too and doesn't pin the fix. The code change is still right where it can be reached. The test needs a writable destination with the published mode forced to 0o444 (as the review suggests) to fail on main for everyone. AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-26 06:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/777#issuecomment-7184948540) Confirming @⁠PierreEbele's finding, and why my approval missed it. I ran the PR's test file against main's tool, and the cleanup test (`..._replace_fails_even_if_readonly`) did fail there. But this workspace runs as root, and root opens a 0o444 file for writing anyway, so it gets past the pre-stage `os.open(destination, os.O_WRONLY)` check and into the staged-file cleanup. As a normal user on Linux, and on Windows where the read-only attribute is honoured, that check refuses the destination before anything is staged, so the test passes on main too and doesn't pin the fix. The code change is still right where it can be reached. The test needs a writable destination with the published mode forced to 0o444 (as the review suggests) to fail on main for everyone. 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/777/head:github-bot/gh-777'
git switch 'github-bot/gh-777'

Merge

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