Skip to main content

soma_self_update/
transaction_outcome.rs

1use std::path::PathBuf;
2
3use crate::UpdateError;
4
5#[cfg_attr(not(test), allow(dead_code))]
6#[derive(Clone, Copy)]
7#[repr(u8)]
8pub(crate) enum TestFailpoint {
9    None,
10    AfterMarkerTempSync,
11    AfterMarkerSync,
12    AfterSwap,
13    AfterRollbackRename,
14    FailedRenameAfterMarkerCleanup,
15    FailedRenameAfterBackupCleanup,
16    AfterPreparedMarkerRename,
17    AfterPreparedMarkerRenameWithStateCleanupFailure,
18    PostMarkerModeFailure,
19    PostMarkerDigestFailure,
20    PostMarkerModeFailureWithStateCleanupFailure,
21    PostMarkerDigestFailureWithBackupCleanupFailure,
22    AuthorityAfterPartialWrite,
23    AuthorityBeforeFileSync,
24    AuthorityBeforeDirectorySync,
25}
26
27#[derive(Clone, Debug, Eq, PartialEq)]
28pub enum InstallOutcome {
29    /// The swap and durable installed marker completed; restart into the new executable.
30    RestartRequired {
31        executable: PathBuf,
32        from: String,
33        to: String,
34    },
35    /// The executable was swapped, but a subsequent durability or marker step failed.
36    ///
37    /// The caller must restart into `executable` and let startup recovery inspect the
38    /// prepared marker. Treating this as an ordinary pre-swap failure can leave the old
39    /// process running after its on-disk executable has changed.
40    RestartRequiredIndeterminate {
41        executable: PathBuf,
42        from: String,
43        to: String,
44        error: String,
45    },
46}
47
48#[derive(Clone, Debug, Eq, PartialEq)]
49pub enum ConfirmationOutcome {
50    NoPendingUpdate,
51    Confirmed { version: String },
52}
53
54pub(super) fn indeterminate_restart(
55    executable: PathBuf,
56    previous: String,
57    target: String,
58    error: UpdateError,
59) -> InstallOutcome {
60    InstallOutcome::RestartRequiredIndeterminate {
61        executable,
62        from: previous,
63        to: target,
64        error: error.to_string(),
65    }
66}