diff --git a/crates/clash-verge-profile-store/src/lib.rs b/crates/clash-verge-profile-store/src/lib.rs index de01dab4c..238abd59a 100644 --- a/crates/clash-verge-profile-store/src/lib.rs +++ b/crates/clash-verge-profile-store/src/lib.rs @@ -15,7 +15,10 @@ use std::{ path::{Path, PathBuf}, }; -const JOURNAL: &str = ".profile-refresh"; +pub const RECOVERY_JOURNAL_NAME: &str = ".profile-refresh"; +pub const RECOVERY_ENTRY_NAMES: &[&str] = &[RECOVERY_JOURNAL_NAME, RECOVERY_LOCK_NAME]; + +const RECOVERY_LOCK_NAME: &str = ".profile-refresh.lock"; const DECISION: &str = "decision"; const MAX_DECISION_BYTES: u64 = 4096; const PROFILES: &str = "profiles"; @@ -77,7 +80,7 @@ impl Session { if !platform::supports_redo(&root)? { return Err(StoreError::UnsupportedVolume); } - let lock = platform::open_lock(&root.join(".profile-refresh.lock"))?; + let lock = platform::open_lock(&root.join(RECOVERY_LOCK_NAME))?; lock.lock()?; let session = Self { root, _lock: lock }; session.recover(checkpoint)?; @@ -85,7 +88,7 @@ impl Session { } fn journal(&self) -> PathBuf { - self.root.join(JOURNAL) + self.root.join(RECOVERY_JOURNAL_NAME) } pub fn read_index(&self) -> Result { @@ -572,7 +575,7 @@ fn remove_file_if_exists(path: &Path) -> Result<()> { /// Replays a saved decision before the application creates or loads its index. pub fn recover_pending(root: &Path) -> Result<()> { - match fs::symlink_metadata(root.join(JOURNAL)) { + match fs::symlink_metadata(root.join(RECOVERY_JOURNAL_NAME)) { Ok(_) => Session::open(root).map(drop), Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()), Err(error) => Err(error.into()), diff --git a/src-tauri/src/config/profile_storage.rs b/src-tauri/src/config/profile_storage.rs index 31d4817c2..0c08502a4 100644 --- a/src-tauri/src/config/profile_storage.rs +++ b/src-tauri/src/config/profile_storage.rs @@ -1,9 +1,8 @@ use anyhow::{Result, anyhow}; +use clash_verge_profile_store::RECOVERY_JOURNAL_NAME; use std::sync::OnceLock; use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; -const PROFILE_JOURNAL: &str = ".profile-refresh"; - static PROFILE_IO: RwLock<()> = RwLock::const_new(()); static BLOCKED: OnceLock = OnceLock::new(); @@ -54,7 +53,7 @@ pub(crate) async fn recover_at_startup() -> Result<()> { } async fn journal_exists(root: &std::path::Path) -> Result { - match tokio::fs::symlink_metadata(root.join(PROFILE_JOURNAL)).await { + match tokio::fs::symlink_metadata(root.join(RECOVERY_JOURNAL_NAME)).await { Ok(_) => Ok(true), Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(false), Err(error) => Err(error.into()), @@ -98,7 +97,7 @@ pub(super) async fn commit_refresh( } let result = tokio::task::spawn_blocking(move || { let session = Session::open(&root).map_err(anyhow::Error::from).inspect_err(|error| { - match std::fs::symlink_metadata(root.join(PROFILE_JOURNAL)) { + match std::fs::symlink_metadata(root.join(RECOVERY_JOURNAL_NAME)) { Err(status) if status.kind() == std::io::ErrorKind::NotFound => {} _ => block(error), } diff --git a/src-tauri/src/feat/backup.rs b/src-tauri/src/feat/backup.rs index 2223cba44..022f8117c 100644 --- a/src-tauri/src/feat/backup.rs +++ b/src-tauri/src/feat/backup.rs @@ -11,6 +11,7 @@ use anyhow::{Result, anyhow}; use chrono::Utc; use clash_verge_backup_archive::ValidatedBackup; use clash_verge_logging::{Type, logging}; +use clash_verge_profile_store::RECOVERY_ENTRY_NAMES; use reqwest_dav::list_cmd::ListFile; use serde::Serialize; use std::{fs::File, path::PathBuf}; @@ -168,10 +169,7 @@ async fn restore_files(archive: ValidatedBackup) -> Result<(crate::config: async fn restore_backup_archive(path: PathBuf) -> Result<()> { crate::config::profile_storage::check()?; let archive = AsyncHandler::spawn_blocking(move || -> Result<_> { - Ok(ValidatedBackup::open( - File::open(path)?, - &[".profile-refresh", ".profile-refresh.lock"], - )?) + Ok(ValidatedBackup::open(File::open(path)?, RECOVERY_ENTRY_NAMES)?) }) .await .map_err(|join| anyhow!("backup preflight task failed: {join}"))??;