fix(dns): save the DNS override decision on every runtime replacement

Refs #8431
This commit is contained in:
wonfen
2026-11-03 09:34:16 +08:00
parent 726b2b362f
commit bcbb5e3a58
8 changed files with 53 additions and 11 deletions
+13 -2
View File
@@ -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) {
+3 -2
View File
@@ -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);