Commit graph imsd-messages/interfaces/ImsdMessages-Store.cppm
Author SHA1 Message Date
53bc4797bc
Store, Sync, main: a deleted text stays deleted
imsd keeps a received text until an app deletes it, and a delete can be
refused (polkit, for a session that is not the active one) or time out:
the List after the next start would carry the text again and the app
would import it again (within a run Sync's own record of what it
imported keeps it out). And a deleted row is a tombstone whose bytes
stay in the file until it is rewritten.

The store gains a second table, erased.cdb: the imsd ids of received
texts the user deleted while imsd may still hold their copies, its
format held by the build as the first table's is. Erase and
EraseConversation remember the id before the row goes (a crash between
the two leaves a remembered id, never a text that comes back; a
remembering the store refuses refuses the delete), ImsdIds folds the
remembered ids in, so Sync's `known` keeps a List from importing them,
and ForgetErased drops the ids a List no longer carries — of those
remembered before that List was sent: an id remembered while it was in
flight waits for the next (FetchList's `before` snapshot). Sync's Erase
and EraseConversation go to the store; Fail and the Send continuation
check that the row still exists, so a text deleted while its Send is in
flight takes no late word, and a late answer for a deleted message finds
no row and is logged. main compacts both files at start when either
holds deleted rows or bytes an update or a delete orphaned (a state
reason replaced by another can leave some, so a start after a send may
rewrite both with nothing deleted), and opens the store again on what is
there if the rewrite failed: a deleted text's bytes leave the files at
the next start (a resident instance keeps them until then — nothing
holds a row id across the rewrite but the app itself).

Tested: tests/Store — the remembered ids across a reopen and as known, a
deleted sent text's id not remembered, the ids imsd no longer lists
forgotten, the bytes of deleted texts and forgotten ids gone after the
Compact and a reopen while the kept ones stay, a forgotten id alone
enough for a Compact, the second file private and rewritten with the
first; tests/Sync — a message deleted while it is sending (its late
answers write nothing and are logged), a received text imported,
remembered when deleted and forgotten when no longer listed, a text
signalled while a List is in flight kept by the List sent before the
delete — which forgets the id remembered before it went out — and
forgotten by the next, and a state for another client's text leaving
every message alone.
2026-11-18 01:12:27 +01:00
9707c9fa26
Store: the message database on Crafter.DB
One table without an ordered column: Crafter.DB enforces the order on
every write, and a List() import after a restart can carry an older
stamp than the last row, so a conversation is sorted on read. A row
carries the plan it was written under, the SIM's country code and its
operator, a column each. Messages are looked up by imsd id (unique
across imsd's runs by its run token: an id names one message, and an
empty one — a text imsd has not answered yet — none); read marks and
deletes go per message and per conversation; every write but a Compact
is caught at this one boundary — a store that refuses one (Crafter.DB's
IOError: the disk full, the file system read-only) answers nullopt from
Add, false or a count of 0 (a row appended before its Flush failed is
tombstoned; an in-place write whose Flush failed stays in the row as the
process reads it; SetState's state and imsd's id land in place even when
a reason cannot — the id is inline in the row, 64 bytes as imsd bounds
it, one past that refused rather than thrown), and tells its
onWriteState listener once of the refusal and once of the next write
that got room, which is one that grew a file: Crafter.DB allocates its
extents, so a write that fit the ones it had (an in-place one, a short
row) is no recovery. So a refused write ends no caller's process and the
app's banner can say so. A lock file beside the table, held for the
store's life, makes a second store on the same directory throw
LockedError (the table's own lock sits on an inode a Compact replaces);
it is built on Crafter.DB's File and Os — the directory made 0700 at
every component, the file 0600 and never a symlink, a lock that fails
for any reason but another holder an IOError, not a LockedError. Every
change a call answers as made — a row id, true, a count — is committed
before the call returns, so a row Add returned is on disk. The file's
format is held by the build: static_asserts on the row's size and layout
fingerprint (Crafter.DB's Layout) and on the stored values of Direction
and MessageState, so a column changed without a version bump fails the
build and not a user's open, and an enumerator moved fails it where an
open would misread the stored states without a word.

Tested: tests/Store in a temp directory: the round trip, the sort of a
later-appended older message, the updates, the lookup by imsd id and an
erased row's, an id past imsd's bound refused, the lock from a second
open, persistence across a reopen, Compact, a row kept by a child
process that ends without a flush, the private file modes, and a write
refused under the file-size limit (told once with its reason, the rows
before it standing, an in-place write going through and telling nothing,
a state landing without its refused reason and imsd's id beside it, the
next Add after the limit's lifting telling of the recovery once), and a
Flush failing after its Append (the descriptor pointed at /dev/null for
the one write) tombstoning the row Add refused.
2026-11-18 01:12:27 +01:00
3d635a6f9d
project: the repository skeleton
The SMS app for imsd's net.catcrafts.IMS1.Messaging interface starts
here: the licence (GPL-3.0-only), FUNDING.yml, README and AGENTS, a
project.cpp with the three build products (imsd-messages-core: std and
Crafter.DB; imsd-messages-bus: GLib; the imsd-messages executable),
their module units as stubs, the version constant, the bundled Noto Sans
font with its OFL text, and the first test. This commit is the base every
later range is reviewed against.

Tested: crafter-build builds the three products and --version answers,
crafter-build test passes the one test, lint and format --check are clean
on every text rule and on the AST rules for the eleven files without a
global module fragment; the four files that include gio/gio.h are not
parsed by the lint driver's libclang (no C++ standard library on its
include path: 'type_traits' file not found), which is a Crafter.Build
matter.
2026-10-17 23:14:00 +02:00