Skip to main content

ic_backup/ops/persistence/artifact_commit/
mod.rs

1//! Module: `persistence::artifact_commit`
2//!
3//! Responsibility: durably publish one verified snapshot artifact directory.
4//! Does not own: snapshot download, journal transitions, or manifest creation.
5//! Boundary: accepts journal-bound sibling paths and expected checksum bytes.
6
7use crate::ops::persistence::PersistenceError;
8
9use std::path::Path;
10
11/// Result of publishing a temporary artifact or recovering its published tree.
12#[derive(Clone, Copy, Debug, Eq, PartialEq)]
13pub enum ArtifactCommitOutcome {
14    /// The verified staging tree was published.
15    Published,
16    /// The verified canonical tree was adopted after a lost publication reply.
17    Recovered,
18}
19
20/// Durably publish or recover one checksum-verified snapshot directory.
21///
22/// The caller owns the sibling parent and excludes other writers. A complete
23/// canonical tree may remain after an IO failure; reconcile it on the next call.
24///
25/// # Errors
26/// Rejects conflicting paths, changed bytes, unsafe entries and IO failures.
27pub fn commit_artifact_directory(
28    temporary: &Path,
29    canonical: &Path,
30    expected_checksum: &str,
31) -> Result<ArtifactCommitOutcome, PersistenceError> {
32    #[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
33    {
34        supported::commit_with_hook(temporary, canonical, expected_checksum, |_, _| Ok(()))
35    }
36
37    #[cfg(not(any(target_os = "linux", target_os = "android", target_vendor = "apple")))]
38    {
39        let _ = (temporary, canonical, expected_checksum);
40        Err(PersistenceError::ArtifactCommitUnsupportedPlatform {
41            platform: std::env::consts::OS,
42        })
43    }
44}
45
46#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
47mod supported;
48
49#[cfg(all(
50    test,
51    any(target_os = "linux", target_os = "android", target_vendor = "apple")
52))]
53mod regressions;
54#[cfg(all(
55    test,
56    any(target_os = "linux", target_os = "android", target_vendor = "apple")
57))]
58mod tests;