mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-03 04:00:23 +08:00
fix(profile): recover interrupted subscription refreshes
Keep subscription body and index writes recoverable, and coordinate startup, readers, backup, and Draft publication around the transaction.
This commit is contained in:
@@ -277,20 +277,22 @@ pub async fn create_backup() -> Result<(String, PathBuf), Error> {
|
||||
let file = AsyncHandler::spawn_blocking(move || std::fs::File::create(&value)).await??;
|
||||
let mut archive = BackupWriter::new(file)?;
|
||||
|
||||
if let Ok(mut entries) = fs::read_dir(dirs::app_profiles_dir()?).await {
|
||||
while let Some(entry) = entries.next_entry().await? {
|
||||
let path = entry.path();
|
||||
if path.is_file() {
|
||||
let file_name_os = entry.file_name();
|
||||
let file_name = file_name_os
|
||||
.to_str()
|
||||
.ok_or_else(|| anyhow::Error::msg("Invalid file name encoding"))?;
|
||||
let mut entry = archive.start_profile(file_name)?;
|
||||
let file_content = fs::read(&path).await?;
|
||||
entry.write_all(&file_content)?;
|
||||
}
|
||||
let profile_guard = crate::config::profile_storage::read().await?;
|
||||
let mut entries = fs::read_dir(dirs::app_profiles_dir()?).await?;
|
||||
while let Some(entry) = entries.next_entry().await? {
|
||||
let path = entry.path();
|
||||
if path.is_file() {
|
||||
let file_name_os = entry.file_name();
|
||||
let file_name = file_name_os
|
||||
.to_str()
|
||||
.ok_or_else(|| anyhow::Error::msg("Invalid file name encoding"))?;
|
||||
let mut entry = archive.start_profile(file_name)?;
|
||||
let file_content = fs::read(&path).await?;
|
||||
entry.write_all(&file_content)?;
|
||||
}
|
||||
}
|
||||
let profile_index = fs::read(dirs::profiles_path()?).await?;
|
||||
drop(profile_guard);
|
||||
|
||||
archive
|
||||
.start_file(dirs::CLASH_CONFIG)?
|
||||
@@ -314,9 +316,7 @@ pub async fn create_backup() -> Result<(String, PathBuf), Error> {
|
||||
.write_all(&fs::read(&dns_config_path).await?)?;
|
||||
}
|
||||
|
||||
archive
|
||||
.start_file(dirs::PROFILE_YAML)?
|
||||
.write_all(&fs::read(dirs::profiles_path()?).await?)?;
|
||||
archive.start_file(dirs::PROFILE_YAML)?.write_all(&profile_index)?;
|
||||
archive.finish()?;
|
||||
Ok((zip_file_name, zip_path))
|
||||
}
|
||||
|
||||
@@ -231,6 +231,8 @@ impl CoreManager {
|
||||
pub async fn init(&self) -> Result<bool> {
|
||||
const MAX_PORT_FALLBACK_RETRIES: usize = 3;
|
||||
|
||||
crate::config::profile_storage::check()?;
|
||||
|
||||
if let Some(reason) = crate::config::Config::startup_core_block_reason() {
|
||||
anyhow::bail!("core startup blocked after mixed proxy port fallback failure: {reason}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user