struct Staged {
scratch: PathBuf,
path: PathBuf,
committed: bool,
}Expand description
A file’s next contents, written and synced beside its final path but not yet renamed over it.
The shape didbot-pds’s write-ahead log gives its compaction: the
replacement is built whole, 0600, at a scratch path, and one
rename(2) makes it the file. A crash before the rename leaves the old
file as it was, plus a scratch file the next write removes; a crash after
it leaves the new one. The directory is synced after the rename, because
on most filesystems a rename that has not been durably recorded in its
parent can be undone by a power cut that kept the file it pointed at.
Dropped without commit, it removes its scratch file, so
a save that fails partway leaves no private key under a name nothing
reads.
Fields§
§scratch: PathBuf§path: PathBuf§committed: boolImplementations§
Source§impl Staged
impl Staged
Sourcefn new(path: &Path, contents: &[u8]) -> Result<Self, StorageError>
fn new(path: &Path, contents: &[u8]) -> Result<Self, StorageError>
Writes contents, 0600, to a scratch file beside path.
Sourcefn json<T: Serialize>(path: &Path, value: &T) -> Result<Self, StorageError>
fn json<T: Serialize>(path: &Path, value: &T) -> Result<Self, StorageError>
Serialises value and stages it beside path.
Sourcefn commit(self) -> Result<(), StorageError>
fn commit(self) -> Result<(), StorageError>
Renames the scratch file over its final path, and makes that durable.