From f3d8904fc7e8169eb04bd47900cffdcb43e06de4 Mon Sep 17 00:00:00 2001 From: Karim Jerbi Date: Mon, 10 Aug 2026 23:49:43 +0100 Subject: [PATCH] fix(alias): only advance the migration marker after the merge persists Advancing ocad.pgp.version (or the web counterpart) could succeed while the merged alias table write failed, so a later launch skipped migration against a stale file and permanently lost the new aliases. Gate the version write on the alias-table write (native fs::write / web set_item) succeeding. --- src/app/alias.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/app/alias.rs b/src/app/alias.rs index 66c479cf5..fc305430c 100644 --- a/src/app/alias.rs +++ b/src/app/alias.rs @@ -180,14 +180,17 @@ pub(super) fn load_aliases() -> FxHashMap { .map(|vp| read_alias_version(&vp)) .unwrap_or(0); if migrate_aliases(&mut map, seen) { - // Persist the merged table and advance the marker so the - // next boot skips the already-delivered aliases. + // Persist the merged table, and only if that succeeds advance + // the version marker so a later launch retries the merge + // (otherwise the new aliases would be lost for good while the + // marker claimed they were delivered). if let Some(dir) = path.parent() { let _ = std::fs::create_dir_all(dir); } - let _ = std::fs::write(&path, to_pgp(&map)); - if let Some(vp) = alias_version_file_path() { - let _ = std::fs::write(&vp, DEFAULT_ALIASES_VERSION.to_string()); + if std::fs::write(&path, to_pgp(&map)).is_ok() { + if let Some(vp) = alias_version_file_path() { + let _ = std::fs::write(&vp, DEFAULT_ALIASES_VERSION.to_string()); + } } } map @@ -220,11 +223,18 @@ pub(super) fn load_aliases() -> FxHashMap { let mut map = parse_pgp(&body); let seen = read_alias_version_web(); if migrate_aliases(&mut map, seen) { - let _ = storage.set_item(WEB_ALIAS_KEY, &to_pgp(&map)); - let _ = storage.set_item( - WEB_ALIAS_VERSION_KEY, - &DEFAULT_ALIASES_VERSION.to_string(), - ); + // Only advance the version marker once the migrated table is + // actually stored, so a failed set_item leaves the marker + // behind and the merge is retried next launch. + if storage + .set_item(WEB_ALIAS_KEY, &to_pgp(&map)) + .is_ok() + { + let _ = storage.set_item( + WEB_ALIAS_VERSION_KEY, + &DEFAULT_ALIASES_VERSION.to_string(), + ); + } } map }