Skip to main content

Module file_write

Module file_write 

Source
Expand description

Writing the user’s files in place: atomic replacement and per-file locks.

Every server endpoint that rewrites an existing note — the editor, task toggles, flashcard reviews, moves and the link rewriting a move triggers — goes through here, so they agree on two things:

  • Atomic replacement (atomic_write, implemented by mbr_core::vault::LocalVault and re-exported here): a temp file with a name of its own, beside the target, renamed over it, carrying the target’s permissions.
  • Serialization (FileWriteLocks): a read-patch-write cycle on one file excludes every other one on the same file, so no write is silently overwritten by a second writer that read the older text.

Knows nothing about HTTP; callers map std::io::Error themselves.

Structs§

FileWriteLocks
One async mutex per file, for code that reads a file, patches it and writes it back.

Functions§

atomic_write
Atomically writes bytes to path (temp file in the same dir + rename).
create_unique_temp_file
Creates a fresh temp file beside a write target, for a write-then-rename.