Skip to content

#1871: a mailbox in a Cryptomator vault is saved every time, not only the first - #2003

Open
codeiou wants to merge 1 commit into
UCSLabs:mainfrom
codeiou:fix-1871-fuse-save
Open

codeiou wants to merge 1 commit into
UCSLabs:mainfrom
codeiou:fix-1871-fuse-save

Conversation

@codeiou

@codeiou codeiou commented Nov 26, 2026 •

Copy link
Copy Markdown

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_APPEND refused; O_WRONLY|O_APPEND, O_RDWR and 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):

  • A pack is opened for appending only, the pack that is there and a new one alike.
  • What a save wrote 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 while the writer writes to that pack. Writing still goes through O_APPEND and 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.rs sync_pack, store.rs append (the mailbox file itself), crates/net/src/update_download.rs and xtask/src/affected.rs already open for appending only.
  • store_pack.rs wipe opens for reading and writing without appending, which the vault allows.

How it was checked

All on Linux (Debian 13, Rust 1.95.0):

  • The test. 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. On main it fails with headers-1.pack is open for reading and appending at once (flags ["2102002"]); with this change it passes.
  • The engine's tests. 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 on main here (gz: application/x-etherpeek (*.apc.gz) is missing; cf. Engine test fails on a desktop with LibreOffice: *.doc has two MIME types #1886).
  • Clippy. cargo +1.98.1 clippy -p mailcraft-engine --all-targets -- -D warnings (CI's toolchain) passes.
  • The rest of CI's cheap tier. cargo xtask ci with XTASK_CI_ONLY=fmt,assets,spdx,test-files,workflows,layers,wasm-clock,i18n,release-notes,docs-log: all 10 steps pass.
  • The browser build. cargo check --target wasm32-unknown-unknown -p mailcraft-engine passes; its 2 warnings are in other files and are there on main.
  • In the app. The release build on Linux, with its own settings folder under Xvfb, and the mailbox in a folder where a stand-in for the vault (a library loaded with LD_PRELOAD) refuses O_RDWR|O_APPEND on 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.
    • Before: the second and later saves failed with the reporter's message, at quit too, and 1 of the 3 messages was left.
    • After: no save failed, headers-1.pack holds all three blocks, and all 3 messages are there.
    • Without the stand-in: 3 of 3, before and after.

Not run: Windows and macOS (the change uses no platform-specific code; open_pack is how the module already reads packs everywhere), a real Cryptomator vault, and the whole of cargo xtask ci (clippy and the tests of the whole workspace, cargo-deny).

  • cargo xtask ci passes (only the parts listed above ran)
  • A crash or data-loss fix has its regression test
  • "Allow edits by maintainers" is ticked (the box beside Create pull request)
  • I have signed the CLA, or will by commenting on this pull request

Human-reviewed, AI-assisted, nobody's mailbox harmed.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where changes to mailboxes stored in encrypted folders, such as Cryptomator vaults, could fail to save after the first save. Subsequent saves now work as expected, helping ensure your latest mailbox changes are preserved when MailCraft closes.

…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.
@codeiou
codeiou requested a review from benandez as a code owner November 26, 2026 21:31
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Every author has signed the CLA. Thank you.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Pack writers now open pack files with append-only handles and use a separate read handle to verify written blocks. A Linux-only test checks the handle flags for existing and newly created packs. A release note describes repeated-save failures in encrypted folders.

Changes: Pack append and verification

Layer / File(s) Summary
Append-only writing and verification
crates/engine/src/store_pack.rs, crates/engine/src/store_pack_tests.rs, packaging/release-notes.d/fixes/1871.md
Pack writers use append-only handles. Writer::append reads back written data through a separate read handle and checks its length and SHA-256. A Linux-only test checks that no pack handle is both readable and append-enabled. The release note describes repeated-save failures in encrypted folders.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to fe1ef · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the issue number and describes the fix: a mailbox in a Cryptomator vault is saved on every save, not only the first. The changeset opens header packs for append only and reads back thr…
Description check Passed The description follows the repository template. It has the closing reference (Closes #1871), a user-facing section explaining the symptom and cause, a detailed How it was checked section with tests a…
Linked Issues check Passed [#1871] Requirement: stop opening an existing header pack with read and append on one handle, which the Cryptomator FUSE volume rejects with EIO. The change in crates/engine/src/store_pack.rs (Writer)…
Out of Scope Changes check Passed The coding changes are limited to the fix path. crates/engine/src/store_pack.rs changes the Writer open mode and adds the separate read-only verification handle. crates/engine/src/store_pack_tests.rs …
Full details: Title check

Explanation

The title names the issue number and describes the fix: a mailbox in a Cryptomator vault is saved on every save, not only the first. The changeset opens header packs for append only and reads back through a separate read-only handle, which addresses that failure. The title is specific and matches the main change, though it does not name the technical mechanism.

Full details: Description check

Explanation

The description follows the repository template. It has the closing reference (Closes #1871), a user-facing section explaining the symptom and cause, a detailed How it was checked section with tests and build results, and the checklist. The regression-test item is ticked and the crash/data-loss fix has a test (the /proc/self/fdinfo test). Some items remain unticked: cargo xtask ci is only partly run, which the author states explicitly, and the maintainer-edits and CLA boxes are not ticked. These are acknowledged gaps, not missing sections, so the description is mostly complete.

Full details: Linked Issues check

Explanation

[#1871] Requirement: stop opening an existing header pack with read and append on one handle, which the Cryptomator FUSE volume rejects with EIO. The change in crates/engine/src/store_pack.rs (Writer) opens packs for appending only, for both existing and newly created packs. The read-back that verifies written bytes uses a separate read-only handle (open_pack), opened before writing. This matches the issue's suggested approach. The read-back still checks length and SHA-256, so the check against another concurrent appender is kept. The regression test store::tests::pack_tests::a_pack_is_appended_to_through_a_handle_that_never_reads checks handle flags via /proc/self/fdinfo and is reported to fail on main and pass with the change. The issue's broader suggestion of a fallback or clearer error for FUSE vaults is phrased as optional ('would help'), so it is not a required coding item here. Basis: PR description and change summary. The diff itself was not re-read in this assessment. Real Cryptomator vault testing was not performed, as the PR states.

Full details: Out of Scope Changes check

Explanation

The coding changes are limited to the fix path. crates/engine/src/store_pack.rs changes the Writer open mode and adds the separate read-only verification handle. crates/engine/src/store_pack_tests.rs adds the Linux regression test for that behavior. packaging/release-notes.d/fixes/1871.md adds a release note for the user-visible fix. The PR description states that other append and read/write sites were reviewed and left unchanged, and it gives reasons. No unrelated functional change appears in the summary. Ignored docs/log.d/ROADMAP files for 1871 were excluded from review and were not inspected; they are documentation and do not affect this assessment.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 756df9e and fe1efb2.

Files ignored due to path filters: 2

  • docs/log.d/ROADMAP/progress/1871.md is excluded by !docs/**
  • docs/log.d/ROADMAP/revisions/1871.md is excluded by !docs/**
Files selected for processing: 3

  • crates/engine/src/store_pack.rs
  • crates/engine/src/store_pack_tests.rs
  • packaging/release-notes.d/fixes/1871.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@sonarqubecloud

Copy link
Copy Markdown

@codeiou

codeiou commented Nov 26, 2026

Copy link
Copy Markdown
Author

I have read the MailCraft CLA and I agree to it.

github-actions Bot added a commit that referenced this pull request Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Saving fails with EIO in a Cryptomator vault: headers pack is reopened with read+append

1 participant