fix: report verified orbit capture outcomes
This commit is contained in:
@@ -202,10 +202,25 @@ impl Vault {
|
||||
}
|
||||
|
||||
pub fn prune_with_decay(&mut self, preset: &str) -> Result<Vec<Uuid>> {
|
||||
let policy = DecayPolicy::from_preset(preset);
|
||||
let snaps = self.list_snapshots()?;
|
||||
let refs: Vec<SnapshotRef> = snaps
|
||||
.iter()
|
||||
self.prune_snapshots(preset, snaps.into_iter())
|
||||
}
|
||||
|
||||
pub fn prune_orbit_with_decay(&mut self, orbit_id: Uuid, preset: &str) -> Result<Vec<Uuid>> {
|
||||
let snaps = self.list_snapshots()?;
|
||||
self.prune_snapshots(
|
||||
preset,
|
||||
snaps.into_iter().filter(|s| s.manifest.orbit_id == orbit_id),
|
||||
)
|
||||
}
|
||||
|
||||
fn prune_snapshots(
|
||||
&mut self,
|
||||
preset: &str,
|
||||
snapshots: impl Iterator<Item = StoredSnapshot>,
|
||||
) -> Result<Vec<Uuid>> {
|
||||
let policy = DecayPolicy::from_preset(preset);
|
||||
let refs = snapshots
|
||||
.map(|s| SnapshotRef {
|
||||
id: s.id,
|
||||
taken_at: s.taken_at,
|
||||
@@ -268,4 +283,36 @@ mod tests {
|
||||
vault.snapshot(manifest, b"x", true).unwrap();
|
||||
assert!(vault.list_snapshots().unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn orbit_decay_keeps_other_orbits_recoverable() {
|
||||
let dir = tempdir().unwrap();
|
||||
let mut vault = Vault::init(dir.path(), "secret").unwrap();
|
||||
let orbit_id = Uuid::new_v4();
|
||||
let other_id = Uuid::new_v4();
|
||||
let now = DateTime::from_timestamp(1_730_000_000, 0).unwrap();
|
||||
for (index, id) in [orbit_id, orbit_id, other_id].into_iter().enumerate() {
|
||||
let manifest = SnapshotManifest {
|
||||
snapshot_id: Uuid::new_v4(),
|
||||
orbit_id: id,
|
||||
orbit_name: "same name".into(),
|
||||
labels: vec![],
|
||||
provider: "filesystem".into(),
|
||||
paths: vec![],
|
||||
restore_hints: serde_json::json!({}),
|
||||
};
|
||||
vault
|
||||
.snapshot_at(manifest, b"x", false, now - chrono::Duration::seconds(index as i64))
|
||||
.unwrap();
|
||||
}
|
||||
let pruned = vault
|
||||
.prune_orbit_with_decay(orbit_id, "month-of-weeklies")
|
||||
.unwrap();
|
||||
assert_eq!(pruned.len(), 1);
|
||||
assert!(vault
|
||||
.list_snapshots()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|s| s.manifest.orbit_id == other_id));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user