refactor(subscription): keep profile writes outside proxy fallback

This commit is contained in:
Tunglies
2026-12-03 17:20:42 +08:00
parent 18f733fca9
commit 041454be57
4 changed files with 30 additions and 22 deletions
+12 -4
View File
@@ -1,5 +1,5 @@
use crate::{
config::{Config, PrfOption, fetch_remote_refresh, profiles::apply_remote_refresh_safe},
config::{Config, PrfOption, download_subscription, prepare_remote_refresh, profiles::apply_remote_refresh_safe},
core::{
CoreManager, handle,
notify::{NoticeStatus, Refresh, announce},
@@ -101,7 +101,7 @@ async fn perform_profile_update(
}
tracing::Span::current().record("strategy", name);
let started = std::time::Instant::now();
let result = fetch_remote_refresh(url, options.as_ref()).await;
let result = download_subscription(url, options.as_ref()).await;
let elapsed_field = match strategy {
Strategy::Configured => "configured_elapsed",
Strategy::Clash => "clash_elapsed",
@@ -123,9 +123,17 @@ async fn perform_profile_update(
)
.await;
let last_err = match result {
Ok((strategy, refresh)) => {
Ok((strategy, downloaded)) => {
// A persistence error must not replay a successful download with another transport.
apply_remote_refresh_safe(uid, refresh).await?;
let profiles = Config::profiles().await;
let snapshot = profiles.latest_arc();
let current = snapshot.get_item(uid)?;
anyhow::ensure!(
current.itype.as_deref() == Some("remote") && current.url.as_deref() == Some(url),
"profile source changed during refresh"
);
let refresh = prepare_remote_refresh(downloaded, merged_opt.as_ref()).await?;
apply_remote_refresh_safe(uid, url, refresh).await?;
if !matches!(strategy, Strategy::Configured) {
handle::Handle::notice(NoticeStatus::UpdateWithClashProxy, profile_name.as_str());
}