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