fix(backup): distinguish staging failures from live restore failures

This commit is contained in:
Tunglies
2026-12-04 01:48:34 +08:00
parent 4e50ea0678
commit 338c3f67fa
+19 -25
View File
@@ -53,10 +53,11 @@ async fn apply_backup(archive: BackupArchive<File>) -> Result<()> {
restored.webdav_url.clone_from(&live.webdav_url);
restored.webdav_username.clone_from(&live.webdav_username);
restored.webdav_password.clone_from(&live.webdav_password);
if let Err(error) = restored.save_file().await {
profile_storage::block_restore(&error);
return Err(error);
}
restored
.save_file()
.await
.context("backup files were restored, but the live WebDAV settings could not be saved")
.inspect_err(profile_storage::block_restore)?;
draft.discard();
Ok((profiles, restored))
})
@@ -227,30 +228,23 @@ async fn validate_restore(
async fn restore_files(archive: BackupArchive<File>, retry: bool) -> Result<(IProfiles, IVerge)> {
let home_dir = app_home_dir()?;
let mut archive = validate_restore(archive, &home_dir, retry).await?;
AsyncHandler::spawn_blocking(move || -> Result<()> {
let extracted = archive.extract_to(&home_dir).map_err(anyhow::Error::from);
if let Err(error) = &extracted {
profile_storage::block_restore(error);
}
extracted
})
.await
.map_err(|join| {
let error = anyhow!("backup extraction task failed: {join}");
profile_storage::block_restore(&error);
error
})??;
let loaded = async {
let mut archive = validate_restore(archive, &home_dir, retry)
.await
.context("backup staging failed before live files were changed")?;
AsyncHandler::spawn_blocking(move || archive.extract_to(&home_dir))
.await
.map_err(anyhow::Error::from)
.and_then(|extracted| extracted.map_err(Into::into))
.context("backup restore failed while writing live files; a complete restore may be required")
.inspect_err(profile_storage::block_restore)?;
async {
let verge = help::read_yaml::<IVerge>(&verge_path()?).await?;
let profiles = load_profiles_unlocked().await?;
Ok((profiles, verge))
Ok::<_, anyhow::Error>((profiles, verge))
}
.await;
if let Err(error) = &loaded {
profile_storage::block_restore(error);
}
loaded
.await
.context("backup files were restored, but the restored settings could not be loaded")
.inspect_err(profile_storage::block_restore)
}
/// Backup creation strips the WebDAV credentials, so the live ones are kept.