…ot only the first
Since UCSLabs#1376 a pack of header lines was opened for reading and appending
through one handle, so that a save could read back through it what it
wrote. Cryptomator's file system won't give one handle both for a file
that is there (its FUSE volume says EIO), so with the mailbox in a vault
every save after the one that made the pack failed, the save at quit too,
and what changed after it was lost.
- store_pack: a pack is opened for appending only, the one there and a
new one alike; what was written is read back through a handle of its
own that only reads (open_pack, which never follows a link), opened
before anything is written and kept for that pack.
- test: the handles a later save and a whole rewrite hold on their pack,
as the kernel records them (/proc/self/fdinfo, Linux): none both reads
and appends.
- release-note, progress-log and revision fragments.
The other places that open a file to append to it (sync_pack, the mailbox
file's own append, the update download) already append only; wipe reads
and writes without appending, which the vault allows.
Human-reviewed, AI-assisted, nobody's mailbox harmed.
Closes #1871.
What changes for the person using MailCraft
A mailbox kept in an encrypted folder, such as a Cryptomator vault, is saved every time again. Since 0.13.0, every save after the first failed there with "its header lines couldn't be written beside the mailbox (Input/output error (os error 5))", the save at quit too, and what had changed after the first save was lost when MailCraft closed.
Cause. Since #1376, a pack of header lines (
mailbox.mailcraft.blobs/headers-<n>.pack) has been opened for reading and appending through one handle, so that a save could read back through it what it wrote. Cryptomator's file system won't give one handle both for a file that is there, and its FUSE volume answers EIO, as the reporter's strace showed (O_RDWR|O_APPENDrefused;O_WRONLY|O_APPEND,O_RDWRand reading alone work). A new pack is made through FUSE's create, which works, so the first save went through and every later one failed.What changed (
crates/engine/src/store_pack.rs,Writer):open_pack, which never follows a link), opened before anything is written and kept while the writer writes to that pack. Writing still goes throughO_APPENDand the read-back is the same check as before, so another program appending at the same moment still makes the save fail rather than name the wrong bytes.This is as wide as the fix needs. Every other place that opens a file to append to it, or to read and write it, was checked, and none needed changing:
store_pack.rssync_pack,store.rsappend(the mailbox file itself),crates/net/src/update_download.rsandxtask/src/affected.rsalready open for appending only.store_pack.rswipeopens for reading and writing without appending, which the vault allows.How it was checked
All on Linux (Debian 13, Rust 1.95.0):
store::tests::pack_tests::a_pack_is_appended_to_through_a_handle_that_never_reads(Linux) asks the kernel how each handle a later save and a whole rewrite hold on their pack was opened (/proc/self/fdinfo), and fails if one both reads and appends. Onmainit fails withheaders-1.pack is open for reading and appending at once (flags ["2102002"]); with this change it passes.cargo test -p mailcraft-engine --no-fail-fast: 3,104 passed, 7 ignored, 1 failed. The failure,opening_kind_tests::the_known_types_cover_what_this_desktop_says, reads this desktop's MIME database and fails the same way onmainhere (gz: application/x-etherpeek (*.apc.gz) is missing; cf. Engine test fails on a desktop with LibreOffice: *.doc has two MIME types #1886).cargo +1.98.1 clippy -p mailcraft-engine --all-targets -- -D warnings(CI's toolchain) passes.cargo xtask ciwithXTASK_CI_ONLY=fmt,assets,spdx,test-files,workflows,layers,wasm-clock,i18n,release-notes,docs-log: all 10 steps pass.cargo check --target wasm32-unknown-unknown -p mailcraft-enginepasses; its 2 warnings are in other files and are there onmain.LD_PRELOAD) refusesO_RDWR|O_APPENDon a file that is there with EIO and allows everything else, as the reporter's strace showed. Three messages with long invented headers were imported and saved one at a time through the control channel, then MailCraft was quit.headers-1.packholds all three blocks, and all 3 messages are there.Not run: Windows and macOS (the change uses no platform-specific code;
open_packis how the module already reads packs everywhere), a real Cryptomator vault, and the whole ofcargo xtask ci(clippy and the tests of the whole workspace, cargo-deny).cargo xtask cipasses (only the parts listed above ran)Human-reviewed, AI-assisted, nobody's mailbox harmed.
Summary by CodeRabbit