Skip to content

Commit cfea1c2

Browse files
Lowercase WasmMemoryPersistence
1 parent c584390 commit cfea1c2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

ic-utils/src/interfaces/management_canister/builders.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,11 @@ impl<'agent, 'canister: 'agent> IntoFuture for CreateCanisterBuilder<'agent, 'ca
524524
pub enum WasmMemoryPersistence {
525525
/// Retain the main memory across upgrades.
526526
/// Used for enhanced orthogonal persistence, as implemented in Motoko
527+
#[serde(rename = "keep")]
527528
Keep,
528529
/// Reinitialize the main memory on upgrade.
529530
/// Default behavior without enhanced orthogonal persistence.
531+
#[serde(rename = "replace")]
530532
Replace,
531533
}
532534

@@ -539,6 +541,16 @@ pub struct CanisterUpgradeOptions {
539541
pub wasm_memory_persistence: Option<WasmMemoryPersistence>,
540542
}
541543

544+
impl Default for CanisterUpgradeOptions {
545+
/// Default: `skip_pre_upgrade = true`, `wasm_memory_persistence = Replace`
546+
fn default() -> Self {
547+
Self {
548+
skip_pre_upgrade: Some(false),
549+
wasm_memory_persistence: Some(WasmMemoryPersistence::Replace),
550+
}
551+
}
552+
}
553+
542554
/// The install mode of the canister to install. If a canister is already installed,
543555
/// using [`InstallMode::Install`] will be an error. [`InstallMode::Reinstall`] overwrites
544556
/// the module, and [`InstallMode::Upgrade`] performs an Upgrade step.
@@ -555,6 +567,22 @@ pub enum InstallMode {
555567
Upgrade(Option<CanisterUpgradeOptions>),
556568
}
557569

570+
impl InstallMode {
571+
/// Fills in all `Option` fields with their default values.
572+
pub fn canonicalize(&self) -> InstallMode {
573+
match self {
574+
Self::Upgrade(u) => {
575+
let mut opts = u.unwrap_or_default();
576+
opts.skip_pre_upgrade.get_or_insert(false);
577+
opts.wasm_memory_persistence
578+
.get_or_insert(WasmMemoryPersistence::Replace);
579+
Self::Upgrade(Some(opts))
580+
}
581+
x => *x,
582+
}
583+
}
584+
}
585+
558586
/// A prepared call to `install_code`.
559587
#[derive(Debug, Clone, CandidType, Deserialize)]
560588
pub struct CanisterInstall {

0 commit comments

Comments
 (0)