From ae2049abe8944d3871e683484ca509f4bbc11bd7 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Tue, 22 Feb 2022 09:19:56 -0500 Subject: [PATCH] make auto-upgrades more explicit --- src/accountmanager.rs | 7 +++++-- src/main.rs | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/accountmanager.rs b/src/accountmanager.rs index 8636542..2f82556 100644 --- a/src/accountmanager.rs +++ b/src/accountmanager.rs @@ -315,17 +315,20 @@ impl Manifest { self.entries.iter().any(|e| e.account_name.is_empty()) } - pub fn auto_upgrade(&mut self) -> anyhow::Result<(), ManifestAccountLoadError> { + /// Performs auto-upgrades on the manifest. Returns true if any upgrades were performed. + pub fn auto_upgrade(&mut self) -> anyhow::Result { debug!("Performing auto-upgrade..."); + let mut upgraded = false; if self.is_missing_account_name() { debug!("Adding missing account names"); for i in 0..self.entries.len() { let account = self.load_account_by_entry(&self.entries[i].clone())?; self.entries[i].account_name = account.lock().unwrap().account_name.clone(); } + upgraded = true; } - Ok(()) + Ok(upgraded) } } diff --git a/src/main.rs b/src/main.rs index 6b916cf..b37e57e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -201,8 +201,14 @@ fn run() -> anyhow::Result<()> { manifest.submit_passkey(passkey); loop { - match manifest.load_accounts() { - Ok(_) => break, + match manifest.auto_upgrade() { + Ok(upgraded) => { + if upgraded { + info!("Manifest auto-upgraded"); + manifest.save()?; + } + break; + }, Err( accountmanager::ManifestAccountLoadError::MissingPasskey | accountmanager::ManifestAccountLoadError::IncorrectPasskey,