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

Merged
leonida/mandy
trigger337 merged 1 commit from fix/text-tables-ro-cleanup into main 2026-11-28 20:17:52 +00:00

Pull request successfully merged and closed

trigger337 commented 2026-11-24 13:13:30 +00:00

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

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 approved these changes 2026-11-24 13:14:14 +00:00
abnalstlll-byte left a comment

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.

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 approved these changes 2026-11-24 13:26:08 +00:00
abnalstlll-byte left a comment

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

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.

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

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

**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 description provided.