Skip to main content

sapphire_framework_sync/
state.rs

1//! Per-path state kept by a replica.
2
3use serde::{Deserialize, Serialize};
4
5use crate::entry::Entry;
6use crate::hash::ContentHash;
7use crate::merge;
8use crate::vv::VersionVector;
9
10/// What is on disk for a path.
11#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
12pub struct DiskState {
13    /// Hash of the file; `None` when there is no file.
14    pub hash: Option<ContentHash>,
15    /// Versions the file on disk reflects. Context of the next local edit.
16    pub seen: VersionVector,
17    /// Change-detection pre-filter: mtime (ns since the epoch) and size when recorded.
18    pub mtime_ns: i64,
19    pub len: u64,
20    /// Wall-clock time (ns since the epoch) the stamp was taken. A file whose mtime is
21    /// within two seconds of this is "racy": filesystems with coarse mtime granularity
22    /// could hide a same-size edit, so it is re-hashed instead of trusted.
23    pub checked_ns: i64,
24}
25
26/// A path's sibling versions, everything merged so far, and what is on disk.
27#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
28pub struct PathState {
29    pub versions: Vec<Entry>,
30    pub seen: VersionVector,
31    pub disk: DiskState,
32}
33
34impl PathState {
35    pub fn winner(&self) -> &Entry {
36        merge::winner(&self.versions)
37    }
38}