mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-08 19:22:44 +08:00
fix(dns): save the DNS override decision on every runtime replacement
Refs #8431
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::core::notify::{Refresh, announce};
|
||||
use crate::{
|
||||
config::{
|
||||
Config, IVerge,
|
||||
runtime::IRuntime,
|
||||
snapshot::{capture_config_files, restore_files},
|
||||
},
|
||||
core::auto_backup::AutoBackupManager,
|
||||
@@ -12,7 +13,7 @@ use crate::{
|
||||
},
|
||||
};
|
||||
use anyhow::Result;
|
||||
use clash_verge_draft::DraftTransaction;
|
||||
use clash_verge_draft::{DraftTransaction, SharedDraft};
|
||||
use clash_verge_logging::{Type, logging_error};
|
||||
use serde_yaml_ng::Mapping;
|
||||
use std::sync::Arc;
|
||||
@@ -108,6 +109,12 @@ async fn ensure_effect(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn sync_dns_of_replaced_runtime(config_write: &MutexGuard<'_, ()>, original: &SharedDraft<IRuntime>) {
|
||||
if !Arc::ptr_eq(original, &Config::runtime().await.data_arc()) {
|
||||
logging_error!(Type::Config, Config::sync_dns_override_locked(config_write).await);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn apply(config_write: &MutexGuard<'_, ()>, patch: Patch<'_>, effects: Effects) -> Result<()> {
|
||||
let manager = CoreManager::global();
|
||||
let update = manager.claim_config_update(config_write)?;
|
||||
@@ -155,12 +162,16 @@ pub(super) async fn apply(config_write: &MutexGuard<'_, ()>, patch: Patch<'_>, e
|
||||
let runtime_path = crate::utils::dirs::app_home_dir()?.join(crate::constants::files::RUNTIME_CONFIG);
|
||||
snapshots.retain(|snapshot| snapshot.path != runtime_path);
|
||||
}
|
||||
return match restore_files(&snapshots).await {
|
||||
let restored = restore_files(&snapshots).await;
|
||||
// After the restore, which would otherwise overwrite the saved decision.
|
||||
sync_dns_of_replaced_runtime(config_write, &original_runtime).await;
|
||||
return match restored {
|
||||
Ok(()) => Err(error),
|
||||
Err(rollback_error) => Err(proxy_control::rollback_failure(error, rollback_error)),
|
||||
};
|
||||
}
|
||||
transaction.commit();
|
||||
sync_dns_of_replaced_runtime(config_write, &original_runtime).await;
|
||||
match patch {
|
||||
Patch::Verge { patch, .. } => {
|
||||
if patch.auto_check_update == Some(false) {
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::{
|
||||
};
|
||||
use anyhow::{Context as _, Result, anyhow, bail};
|
||||
use clash_verge_draft::DraftTransaction;
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use clash_verge_logging::{Type, logging, logging_error};
|
||||
use scopeguard::{ScopeGuard, defer, guard};
|
||||
|
||||
pub async fn probe_listener(request: ListenerProbe) -> Result<ListenerProbeOutcome> {
|
||||
@@ -30,7 +30,7 @@ pub async fn probe_listener(request: ListenerProbe) -> Result<ListenerProbeOutco
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
pub async fn save_proxy_ports(settings: ProxyPortSettings) -> Result<SaveProxyPortsOutcome> {
|
||||
settings.validate()?;
|
||||
let _config_write = Config::lock_config_write().await;
|
||||
let config_write = Config::lock_config_write().await;
|
||||
let manager = CoreManager::global();
|
||||
if !manager.try_start_config_update() {
|
||||
bail!("configuration update is already running");
|
||||
@@ -124,6 +124,7 @@ pub async fn save_proxy_ports(settings: ProxyPortSettings) -> Result<SaveProxyPo
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
logging_error!(Type::Config, Config::sync_dns_override_locked(&config_write).await);
|
||||
// The save landed, so the port the app had borrowed is now irrelevant.
|
||||
let _ = ScopeGuard::into_inner(borrowed_port);
|
||||
announce(Refresh::Clash);
|
||||
|
||||
Reference in New Issue
Block a user