refactor(backup): name the archive before staging verification

This commit is contained in:
Tunglies
2026-12-04 01:48:33 +08:00
parent 6b84c0d625
commit d2f0f3c0c1
2 changed files with 12 additions and 12 deletions
+7 -7
View File
@@ -14,7 +14,7 @@ use crate::{
};
use anyhow::{Context as _, Result, anyhow};
use chrono::Utc;
use clash_verge_backup_archive::ValidatedBackup;
use clash_verge_backup_archive::BackupArchive;
use clash_verge_draft::DraftConflict;
use clash_verge_logging::{Type, logging};
use clash_verge_profile_store::RECOVERY_ENTRY_NAMES;
@@ -40,7 +40,7 @@ async fn finalize_restored_verge_config(
webdav_url: Option<String>,
webdav_username: Option<String>,
webdav_password: Option<String>,
archive: ValidatedBackup<File>,
archive: BackupArchive<File>,
) -> Result<()> {
let config_write = Config::lock_config_write().await;
let profiles_draft = Config::profiles().await;
@@ -169,10 +169,10 @@ async fn restore_input_path(staged: &Path, home: &Path, name: &str, retry: bool)
}
async fn validate_restore(
mut archive: ValidatedBackup<File>,
mut archive: BackupArchive<File>,
home_dir: &Path,
retry: bool,
) -> Result<ValidatedBackup<File>> {
) -> Result<BackupArchive<File>> {
let staging_root = home_dir.to_owned();
let (staged, archive) = AsyncHandler::spawn_blocking(move || -> Result<_> {
let staged = tempfile::tempdir_in(staging_root)?;
@@ -215,7 +215,7 @@ async fn validate_restore(
Ok(archive)
}
async fn restore_files(archive: ValidatedBackup<File>, retry: bool) -> Result<(IProfiles, IVerge)> {
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<()> {
@@ -246,7 +246,7 @@ async fn restore_files(archive: ValidatedBackup<File>, retry: bool) -> Result<(I
/// Backup creation strips the WebDAV credentials, so the live ones are kept.
async fn restore_backup_archive(path: PathBuf) -> Result<()> {
let archive = AsyncHandler::spawn_blocking(move || -> Result<_> {
Ok(ValidatedBackup::open(File::open(path)?, RECOVERY_ENTRY_NAMES)?)
Ok(BackupArchive::open(File::open(path)?, RECOVERY_ENTRY_NAMES)?)
})
.await
.map_err(|join| anyhow!("backup preflight task failed: {join}"))??;
@@ -499,7 +499,7 @@ mod tests {
if include_body {
writer.start_profile("r.yaml")?.write_all(b"proxies: []\n")?;
}
Ok(ValidatedBackup::open(writer.finish()?, RECOVERY_ENTRY_NAMES)?)
Ok(BackupArchive::open(writer.finish()?, RECOVERY_ENTRY_NAMES)?)
};
let invalid = open_backup(Some(b"items: invalid\n"), false)?;