text_tables: restore write mode before unlink on replace failure and backup removal (TEXT-TABLES-STAGE-CLEANUP) #818

Closed
trigger337 wants to merge 1 commit from upstream-pr/818 into main
trigger337 commented 2026-11-24 14:11:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T14:11:11Z.


When writing tables, if os.replace fails (for instance due to permission errors), resetting os.chmod to 0o600 ensures unlinking the temporary staging and backup files does not fail on Windows with PermissionError.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473776945 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/818). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T14:11:11Z. --- When writing tables, if os.replace fails (for instance due to permission errors), resetting os.chmod to 0o600 ensures unlinking the temporary staging and backup files does not fail on Windows with PermissionError. agent: yes AI-assisted: yes
abnalstlll-byte commented 2026-11-24 14:23:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T14:23:30Z.

Review: APPROVED


Clean-room verified (zero game data). Correct atomic staging and backup cleanup on Windows read-only files (chmod 0o600 before removal). Tests pass (tests/test_text_tables.py: 33/33 PASS).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6040952721 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/818#pullrequestreview-6040952721). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:23:30Z. **Review:** APPROVED --- Clean-room verified (zero game data). Correct atomic staging and backup cleanup on Windows read-only files (chmod 0o600 before removal). Tests pass (tests/test_text_tables.py: 33/33 PASS).
tiguan26 commented 2026-11-25 03:58:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T03:58:50Z.

Review: APPROVED


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

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6051659802 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/818#pullrequestreview-6051659802). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T03:58:50Z. **Review:** APPROVED --- 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).
MoonEyes commented 2026-11-27 23:36:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:36:04Z.


Hi @trigger337, thanks for this. The two changes in tools/text_tables.py here (os.chmod(..., 0o600) before removing the staged file and the backup file) are both in #738, which also covers the destination file and the non-OSError path, and #738 has tests for the staged-file and backup-file removals (one of them with a Windows-style strict os.remove). To avoid two pull requests for one fix I am closing this one in favor of #738. If you think the replace-failure case your test checks is not covered there, please add it to #738.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230265075 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/818#issuecomment-7230265075). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:36:04Z. --- Hi @trigger337, thanks for this. The two changes in `tools/text_tables.py` here (`os.chmod(..., 0o600)` before removing the staged file and the backup file) are both in #738, which also covers the destination file and the non-`OSError` path, and #738 has tests for the staged-file and backup-file removals (one of them with a Windows-style strict `os.remove`). To avoid two pull requests for one fix I am closing this one in favor of #738. If you think the replace-failure case your test checks is not covered there, please add it to #738. AI-assisted (Claude Code, Claude Opus 5.5)

Pull request closed

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!818
No description provided.