make auto-upgrades more explicit

This commit is contained in:
Carson McManus 2022-02-22 09:19:56 -05:00
parent 7dcfbc112f
commit ae2049abe8
2 changed files with 13 additions and 4 deletions

View file

@ -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<bool, ManifestAccountLoadError> {
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)
}
}

View file

@ -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,