Open the database read-only for report and trees (closes #8) #72

Merged
clawbot merged 1 commits from issue-8-read-only-report into next 2026-10-03 16:30:20 +02:00
Collaborator

Implements #8.

What changed

  • report and trees open the database read-only: mode=ro, query_only(1), the same busy timeout, no journal_mode. The scan connection settings are unchanged.
  • scan switches the database back to rollback-journal mode whenever it closes it, so between scans the database file alone holds the database.
  • README.md §Database states what report and trees need and how the switch meets a running report.

What the diff does not show

  • The connection change alone is not enough: a read-only connection to a WAL database fails when it cannot create -wal and -shm, and in a writable directory it leaves them behind. Hence the switch, as the plan comment suggested.
  • The switch needs the database to itself. If a report has it open when scan closes, scan warns and leaves it in WAL mode until the next scan; the -wal and -shm files stay, with the database file's permissions, so read-only reports keep working. A test covers this.
  • A scan that starts while a report is still mid-read now waits up to the 10-second busy timeout to enter WAL mode, then fails. Before, that case never waited.
  • In TestRunFatalAfterOpenClosesDatabase the leftover-file check now proves the close only for scan; its comment says so.

Disclosures

  • Judgement call: switch modes at close rather than keep -wal/-shm permanently, or open readers with immutable=1, which is unsafe during a scan.
  • Judgement call: a refused switch is a warning (exit 0), not fatal.
  • The two permission tests skip as root, which ignores file permissions.

Model: opus-5-5

Implements https://git.eeqj.de/sneak/sfdupes/issues/8. ## What changed - `report` and `trees` open the database read-only: `mode=ro`, `query_only(1)`, the same busy timeout, no `journal_mode`. The `scan` connection settings are unchanged. - `scan` switches the database back to rollback-journal mode whenever it closes it, so between scans the database file alone holds the database. - `README.md` §Database states what `report` and `trees` need and how the switch meets a running report. ## What the diff does not show - The connection change alone is not enough: a read-only connection to a WAL database fails when it cannot create `-wal` and `-shm`, and in a writable directory it leaves them behind. Hence the switch, as the plan comment suggested. - The switch needs the database to itself. If a report has it open when `scan` closes, `scan` warns and leaves it in WAL mode until the next scan; the `-wal` and `-shm` files stay, with the database file's permissions, so read-only reports keep working. A test covers this. - A `scan` that starts while a report is still mid-read now waits up to the 10-second busy timeout to enter WAL mode, then fails. Before, that case never waited. - In `TestRunFatalAfterOpenClosesDatabase` the leftover-file check now proves the close only for `scan`; its comment says so. ## Disclosures - Judgement call: switch modes at close rather than keep `-wal`/`-shm` permanently, or open readers with `immutable=1`, which is unsafe during a scan. - Judgement call: a refused switch is a warning (exit 0), not fatal. - The two permission tests skip as root, which ignores file permissions. Model: opus-5-5
clawbot added the needs-review label 2026-10-03 15:01:45 +02:00
clawbot self-assigned this 2026-10-03 15:01:45 +02:00
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot added needs-rebase and removed needs-review labels 2026-10-03 15:42:19 +02:00
clawbot added 1 commit 2026-10-03 16:21:42 +02:00
report and trees now connect read-only (mode=ro, query_only, the same
busy timeout) and no longer set the journal mode, which is a write. A
read-only connection to a WAL database still needs its -wal and -shm
files, or write access to the directory to create them, so scan now
switches the database back to rollback-journal mode whenever it closes
it: between scans the file alone holds the database. If a report has
the database open at that moment the switch is refused; scan warns and
the database stays in WAL mode, with its -wal and -shm files, until the
next scan. README §Database states what readers need.

Model: opus-5-5
clawbot force-pushed issue-8-read-only-report from 7e1deb25f7 to 89a861a989 2026-10-03 16:21:42 +02:00 Compare
Author
Collaborator

Rebased onto next; only the TODO.md entry conflicted.

Model: opus-5-5

Rebased onto `next`; only the `TODO.md` entry conflicted. Model: opus-5-5
clawbot added needs-review and removed needs-rebase labels 2026-10-03 16:21:47 +02:00
clawbot merged commit d63d3cc7fc into next 2026-10-03 16:30:20 +02:00
clawbot deleted branch issue-8-read-only-report 2026-10-03 16:30:20 +02:00
Sign in to join this conversation.