Rustidian is a native notes app for Markdown files that I am building in Rust. This post shows how it saves a note without overwriting what another editor wrote.
Rustidian keeps notes as ordinary files. That means a second editor can write the same note while I have unsaved changes. A temporary file avoids a partial write, but the save must also check whether the text it replaces has changed.
This is a reading of the save path in the published 0.1.6 source. Here is the mechanism and its limit.
Remember what the edit started from
A pending save holds the edited text and the original text it expects to replace. Before writing, I read the note from disk and compare it with that original. This excerpt is from PendingSave::write :
let current = fs :: read_to_string ( & self . absolute ) . map_err ( | e | { format! ( "Note was removed or cannot be read. Your changes are still open: {e}" ) } ) ? ; if current != self . original { return Err ( "This note changed outside Rustidian.…