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.
This commit is contained in:
parent
7013aa8cbb
commit
f3d8904fc7
1 changed files with 20 additions and 10 deletions
|
|
@ -180,14 +180,17 @@ pub(super) fn load_aliases() -> FxHashMap<String, String> {
|
||||||
.map(|vp| read_alias_version(&vp))
|
.map(|vp| read_alias_version(&vp))
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
if migrate_aliases(&mut map, seen) {
|
if migrate_aliases(&mut map, seen) {
|
||||||
// Persist the merged table and advance the marker so the
|
// Persist the merged table, and only if that succeeds advance
|
||||||
// next boot skips the already-delivered aliases.
|
// 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() {
|
if let Some(dir) = path.parent() {
|
||||||
let _ = std::fs::create_dir_all(dir);
|
let _ = std::fs::create_dir_all(dir);
|
||||||
}
|
}
|
||||||
let _ = std::fs::write(&path, to_pgp(&map));
|
if std::fs::write(&path, to_pgp(&map)).is_ok() {
|
||||||
if let Some(vp) = alias_version_file_path() {
|
if let Some(vp) = alias_version_file_path() {
|
||||||
let _ = std::fs::write(&vp, DEFAULT_ALIASES_VERSION.to_string());
|
let _ = std::fs::write(&vp, DEFAULT_ALIASES_VERSION.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
map
|
map
|
||||||
|
|
@ -220,11 +223,18 @@ pub(super) fn load_aliases() -> FxHashMap<String, String> {
|
||||||
let mut map = parse_pgp(&body);
|
let mut map = parse_pgp(&body);
|
||||||
let seen = read_alias_version_web();
|
let seen = read_alias_version_web();
|
||||||
if migrate_aliases(&mut map, seen) {
|
if migrate_aliases(&mut map, seen) {
|
||||||
let _ = storage.set_item(WEB_ALIAS_KEY, &to_pgp(&map));
|
// Only advance the version marker once the migrated table is
|
||||||
let _ = storage.set_item(
|
// actually stored, so a failed set_item leaves the marker
|
||||||
WEB_ALIAS_VERSION_KEY,
|
// behind and the merge is retried next launch.
|
||||||
&DEFAULT_ALIASES_VERSION.to_string(),
|
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
|
map
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue