use super::*;
pub(super) fn ensure_exact_checkpoint_cut(
cursor: &RelayCursor,
expected_ordinal: u64,
expected_digest: &str,
) -> Result<()> {
if cursor.ordinal != expected_ordinal || cursor.digest != expected_digest {
bail!(CheckpointDeferred::frontier_moved());
}
Ok(())
}
pub(super) fn validate_checkpoint_barrier_snapshot(
snapshot: &ManagedSessionSnapshot,
command_id: &str,
expected: &RelayCursor,
) -> Result<()> {
ensure!(
snapshot.operational.checkpoint_barrier.as_deref() == Some(command_id),
"checkpoint barrier {command_id} is no longer active"
);
ensure!(
snapshot.operational.checkpoint_ready.as_ref() == Some(expected),
"checkpoint barrier {command_id} has a different ready cursor"
);
if snapshot
.operational
.last_harness_turn_started_ordinal
.is_some_and(|ordinal| ordinal > expected.ordinal)
{
bail!(CheckpointDeferred::harness_turn_during_capture());
}
Ok(())
}
pub(super) fn validate_automatic_checkpoint_barrier_snapshot(
snapshot: &ManagedSessionSnapshot,
command_id: &str,
expected: &RelayCursor,
harness: HarnessKind,
) -> Result<()> {
validate_checkpoint_barrier_snapshot(snapshot, command_id, expected)?;
ensure!(
snapshot.operational.safe_for_checkpoint(harness),
CheckpointDeferred::background_snapshot(&snapshot.operational, harness)
);
Ok(())
}
pub(super) fn remove_uninstalled_checkpoint(path: &Path, error: anyhow::Error) -> anyhow::Error {
match std::fs::remove_file(path) {
Ok(()) => error,
Err(remove_error) if remove_error.kind() == std::io::ErrorKind::NotFound => error,
Err(remove_error) => error.context(format!(
"also failed to remove uninstalled checkpoint {}: {remove_error}",
path.display()
)),
}
}