Revert "refactor: extract load_backup helper"

This reverts commit a54fb99428.
This commit is contained in:
Razvan Dimescu
2026-04-08 05:04:47 +03:00
parent a54fb99428
commit 522e145c22

View File

@@ -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" | "") 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<T: serde::de::DeserializeOwned>(path: &std::path::Path) -> Option<T> {
serde_json::from_str(&std::fs::read_to_string(path).ok()?).ok()
}
/// A conditional forwarding rule: domains matching `suffix` are forwarded to `upstream`. /// A conditional forwarding rule: domains matching `suffix` are forwarded to `upstream`.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ForwardingRule { pub struct ForwardingRule {
@@ -579,7 +572,9 @@ fn install_windows() -> Result<(), String> {
// Preserve an existing useful backup rather than overwriting it with // Preserve an existing useful backup rather than overwriting it with
// numa-managed state (which would be self-referential after uninstall). // numa-managed state (which would be self-referential after uninstall).
let existing: Option<std::collections::HashMap<String, WindowsInterfaceDns>> = let existing: Option<std::collections::HashMap<String, WindowsInterfaceDns>> =
load_backup(&path); std::fs::read_to_string(&path)
.ok()
.and_then(|json| serde_json::from_str(&json).ok());
let has_useful_existing = existing let has_useful_existing = existing
.as_ref() .as_ref()
.map(backup_has_real_upstream_windows) .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), // If a useful backup already exists (at least one non-loopback upstream),
// preserve it — overwriting would destroy the original DNS state when // preserve it — overwriting would destroy the original DNS state when
// re-installing on top of a numa-managed configuration. // re-installing on top of a numa-managed configuration.
let existing_backup: Option<HashMap<String, Vec<String>>> = load_backup(&backup_path()); let existing_backup: Option<HashMap<String, Vec<String>>> =
std::fs::read_to_string(backup_path())
.ok()
.and_then(|json| serde_json::from_str(&json).ok());
let has_useful_existing = existing_backup let has_useful_existing = existing_backup
.as_ref() .as_ref()
.map(backup_has_real_upstream_macos) .map(backup_has_real_upstream_macos)