From 522e145c22ad2b88875ce1940e70738e43647a70 Mon Sep 17 00:00:00 2001 From: Razvan Dimescu Date: Wed, 8 Apr 2026 05:04:47 +0300 Subject: [PATCH] Revert "refactor: extract load_backup helper" This reverts commit a54fb99428fb29da6f6ee2cc365bbb97e31cfbb1. --- src/system_dns.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/system_dns.rs b/src/system_dns.rs index 59e40e7..9d48996 100644 --- a/src/system_dns.rs +++ b/src/system_dns.rs @@ -6,13 +6,6 @@ fn is_loopback_or_stub(addr: &str) -> bool { matches!(addr, "127.0.0.1" | "127.0.0.53" | "0.0.0.0" | "::1" | "") } -/// Load a JSON backup file as `T`, returning `None` if the file is missing -/// or unreadable (rather than erroring — callers fall back to a fresh capture). -#[cfg(any(target_os = "macos", windows))] -fn load_backup(path: &std::path::Path) -> Option { - serde_json::from_str(&std::fs::read_to_string(path).ok()?).ok() -} - /// A conditional forwarding rule: domains matching `suffix` are forwarded to `upstream`. #[derive(Debug, Clone)] pub struct ForwardingRule { @@ -579,7 +572,9 @@ fn install_windows() -> Result<(), String> { // Preserve an existing useful backup rather than overwriting it with // numa-managed state (which would be self-referential after uninstall). let existing: Option> = - load_backup(&path); + std::fs::read_to_string(&path) + .ok() + .and_then(|json| serde_json::from_str(&json).ok()); let has_useful_existing = existing .as_ref() .map(backup_has_real_upstream_windows) @@ -836,7 +831,10 @@ fn install_macos() -> Result<(), String> { // If a useful backup already exists (at least one non-loopback upstream), // preserve it — overwriting would destroy the original DNS state when // re-installing on top of a numa-managed configuration. - let existing_backup: Option>> = load_backup(&backup_path()); + let existing_backup: Option>> = + std::fs::read_to_string(backup_path()) + .ok() + .and_then(|json| serde_json::from_str(&json).ok()); let has_useful_existing = existing_backup .as_ref() .map(backup_has_real_upstream_macos)