text_tables: restore write mode before removing staged and backup files (TEXT-TABLES-RO-CLEANUP) #738

Merged
trigger337 merged 1 commit from upstream-pr/738 into main 2026-11-28 20:17:52 +00:00
trigger337 commented 2026-11-24 13:13:30 +00:00 (Migrated from github.com)

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


On Windows, removing a file marked read-only fails with PermissionError (WinError 5). In tools/text_tables.py:

  1. When destination was read-only, os.chmod(tmp, published_mode(dest)) sets tmp to read-only mode. If a subsequent write fails, rollback attempted os.remove(tmp), which failed on Windows and leaked staging files.
  2. When replacing an existing read-only file, the original destination was backed up to .text_tables-old-*. Upon successful completion, os.remove(backup) failed on Windows because the backup retained the read-only attribute, silently leaking backup files.
  3. If an unexpected BaseException (e.g., interrupt or crash) occurred during the stage/swap loop, rollback was not executed. Catching BaseException guarantees that staged and backup files are cleaned up and original files restored before re-raising non-OSErrors.

Restores write permissions (os.chmod(..., 0o600)) before deleting staged or backup files, and adds regression tests covering read-only failure cleanup, read-only success backup cleanup, and strict read-only deletion simulation.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5472826110 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/738). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T13:13:30Z. --- On Windows, removing a file marked read-only fails with PermissionError (WinError 5). In `tools/text_tables.py`: 1. When destination was read-only, `os.chmod(tmp, published_mode(dest))` sets `tmp` to read-only mode. If a subsequent write fails, rollback attempted `os.remove(tmp)`, which failed on Windows and leaked staging files. 2. When replacing an existing read-only file, the original destination was backed up to `.text_tables-old-*`. Upon successful completion, `os.remove(backup)` failed on Windows because the backup retained the read-only attribute, silently leaking backup files. 3. If an unexpected BaseException (e.g., interrupt or crash) occurred during the stage/swap loop, rollback was not executed. Catching BaseException guarantees that staged and backup files are cleaned up and original files restored before re-raising non-OSErrors. Restores write permissions (`os.chmod(..., 0o600)`) before deleting staged or backup files, and adds regression tests covering read-only failure cleanup, read-only success backup cleanup, and strict read-only deletion simulation. agent: yes AI-assisted: yes
abnalstlll-byte commented 2026-11-24 13:14:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T13:14:14Z.

Review: APPROVED


LGTM. Thorough fix for Windows read-only file removal semantics (os.chmod(..., 0o600) before os.remove) with solid unit test coverage in est_text_tables.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6039822360 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/738#pullrequestreview-6039822360). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T13:14:14Z. **Review:** APPROVED --- LGTM. Thorough fix for Windows read-only file removal semantics (os.chmod(..., 0o600) before os.remove) with solid unit test coverage in est_text_tables.py.
abnalstlll-byte commented 2026-11-24 13:26:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T13:26:08Z.

Review: APPROVED


Audited and verified. Clean-room compliant.

  • Restores 0o600 mode before removing staged/backup files on failure in tools/text_tables.py.
  • Unit tests in tests/test_text_tables.py PASS.
<!-- greyfinch-sync:ubiquitarianism/leonida:review:6039992382 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/738#pullrequestreview-6039992382). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T13:26:08Z. **Review:** APPROVED --- Audited and verified. Clean-room compliant. - Restores 0o600 mode before removing staged/backup files on failure in tools/text_tables.py. - Unit tests in tests/test_text_tables.py PASS.
MoonEyes commented 2026-11-28 20:17:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T20:17:49Z.


Red/green: On main test_text_tables.py fails because a read-only destination leaves a .text_tables-old-*.csv backup behind, and with the PR all 39 tests pass on Windows 11 at OreoFR's (RTX 4070).
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245182079 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/738#issuecomment-7245182079). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T20:17:49Z. --- Red/green: On main test_text_tables.py fails because a read-only destination leaves a .text_tables-old-*.csv backup behind, and with the PR all 39 tests pass on Windows 11 at OreoFR's (RTX 4070). Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 21:43:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:43:27Z.


Verified by OreoFR

  • Base: main 3408969a7 + PR head 13395c437
  • Test: python -I tests/test_text_tables.py
  • Red on main: 1 FAIL (test_successful_write_with_readonly_destination_cleans_up_backup_files: .text_tables-old-*.csv left behind)
  • Green with the PR: 39 OK
  • Verdict: READY (Windows-specific defect: a read-only file cannot be deleted)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246225085 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/738#issuecomment-7246225085). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:43:27Z. --- **Verified by OreoFR** - Base: main `3408969a7` + PR head `13395c437` - Test: `python -I tests/test_text_tables.py` - Red on main: 1 FAIL (test_successful_write_with_readonly_destination_cleans_up_backup_files: .text_tables-old-*.csv left behind) - Green with the PR: 39 OK - Verdict: READY (Windows-specific defect: a read-only file cannot be deleted) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 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!738
No description provided.