diff --git a/components/apps/src/lib.rs b/components/apps/src/lib.rs index 2df6ecd3..ac6762f9 100644 --- a/components/apps/src/lib.rs +++ b/components/apps/src/lib.rs @@ -349,6 +349,13 @@ impl Apps { // TODO: use CLIENT_ID directly let mut filestore = ClientFilestore::new(ADMIN_APP_CLIENT_ID.into(), data.store); let version = data.version.encode(); + + let valid_migrators = migrations::MIGRATORS; + // No migrations if the config failed to load. In that case applications are disabled anyways + let config_error_migrators = &[]; + + let mut used_migrators = valid_migrators; + let mut app = AdminApp::::load_config( trussed, &mut filestore, @@ -356,24 +363,29 @@ impl Apps { version, data.version_string, data.status(), - migrations::MIGRATORS, + valid_migrators, ) .unwrap_or_else(|(trussed, _err)| { data.init_status.insert(InitStatus::CONFIG_ERROR); + used_migrators = config_error_migrators; AdminApp::::with_default_config( trussed, runner.uuid(), version, data.version_string, data.status(), - // No migrations if the config failed to load. In that case applications are disabled anyways - &[], + config_error_migrators, ) }); - const LATEST_MIGRATION: u32 = 0; + let migration_version = used_migrators + .iter() + .map(|m| m.version) + .max() + .unwrap_or_default(); + let migration_success = app - .migrate(LATEST_MIGRATION, data.store, &mut filestore) + .migrate(migration_version, data.store, &mut filestore) .is_ok(); if !migration_success { data.init_status.insert(InitStatus::MIGRATION_ERROR); diff --git a/components/apps/src/migrations.rs b/components/apps/src/migrations.rs index a72b8419..080f6110 100644 --- a/components/apps/src/migrations.rs +++ b/components/apps/src/migrations.rs @@ -7,30 +7,12 @@ pub(crate) const MIGRATION_VERSION_SPACE_EFFICIENCY: u32 = 1; #[cfg(feature = "backend-auth")] pub(crate) const TRUSSED_AUTH_FS_LAYOUT: trussed_auth::FilesystemLayout = - trussed_auth::FilesystemLayout::V0; + trussed_auth::FilesystemLayout::V1; #[cfg(feature = "se050")] pub(crate) const SE050_BACKEND_FS_LAYOUT: trussed_se050_backend::FilesystemLayout = - trussed_se050_backend::FilesystemLayout::V0; + trussed_se050_backend::FilesystemLayout::V1; -/// TODO: When enabling the filesystem layout V1, fido-authenticator will also need to be bump and have its migration enabled -const _: () = { - #[cfg(feature = "backend-auth")] - assert!(matches!( - TRUSSED_AUTH_FS_LAYOUT, - trussed_auth::FilesystemLayout::V0 - )); - #[cfg(feature = "se050")] - assert!(matches!( - SE050_BACKEND_FS_LAYOUT, - trussed_se050_backend::FilesystemLayout::V0 - )); - assert!(MIGRATORS.is_empty()); -}; - -pub(crate) const MIGRATORS: &[Migrator] = &[]; - -// TODO: use when enabling migrations of trussed-auth and se050-backend and of fido-authenticator -const _MIGRATORS: &[Migrator] = &[ +pub(crate) const MIGRATORS: &[Migrator] = &[ // We first migrate the SE050 since this migration deletes data to make sure that the other // migrations succeed even on low block availability #[cfg(feature = "se050")]