fix CI: gate macOS-only helpers behind cfg(target_os = macos)

Move HashMap, PathBuf, numa_data_dir, backup_path inside macOS
cfg blocks so Linux builds don't see unused imports/functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Razvan Dimescu
2026-03-20 11:48:33 +02:00
parent b0f4bb9dc0
commit ae9edb3593

View File

@@ -1,6 +1,4 @@
use std::collections::HashMap;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::path::PathBuf;
use log::info; use log::info;
@@ -150,20 +148,6 @@ pub fn match_forwarding_rule(domain: &str, rules: &[ForwardingRule]) -> Option<S
// --- System DNS configuration (install/uninstall) --- // --- System DNS configuration (install/uninstall) ---
fn numa_data_dir() -> PathBuf {
dirs_or_home().join(".numa")
}
fn dirs_or_home() -> PathBuf {
std::env::var("HOME")
.map(PathBuf::from)
.unwrap_or_else(|_| PathBuf::from("/tmp"))
}
fn backup_path() -> PathBuf {
numa_data_dir().join("original-dns.json")
}
/// Set the system DNS to 127.0.0.1 so all queries go through Numa. /// Set the system DNS to 127.0.0.1 so all queries go through Numa.
/// Saves the original DNS settings for later restoration. /// Saves the original DNS settings for later restoration.
pub fn install_system_dns() -> Result<(), String> { pub fn install_system_dns() -> Result<(), String> {
@@ -199,6 +183,19 @@ pub fn uninstall_system_dns() -> Result<(), String> {
// --- macOS implementation --- // --- macOS implementation ---
#[cfg(target_os = "macos")]
fn numa_data_dir() -> std::path::PathBuf {
let home = std::env::var("HOME")
.map(std::path::PathBuf::from)
.unwrap_or_else(|_| std::path::PathBuf::from("/tmp"));
home.join(".numa")
}
#[cfg(target_os = "macos")]
fn backup_path() -> std::path::PathBuf {
numa_data_dir().join("original-dns.json")
}
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn get_network_services() -> Result<Vec<String>, String> { fn get_network_services() -> Result<Vec<String>, String> {
let output = std::process::Command::new("networksetup") let output = std::process::Command::new("networksetup")
@@ -234,6 +231,8 @@ fn get_dns_servers(service: &str) -> Result<Vec<String>, String> {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn install_macos() -> Result<(), String> { fn install_macos() -> Result<(), String> {
use std::collections::HashMap;
let services = get_network_services()?; let services = get_network_services()?;
let mut original: HashMap<String, Vec<String>> = HashMap::new(); let mut original: HashMap<String, Vec<String>> = HashMap::new();
@@ -274,6 +273,8 @@ fn install_macos() -> Result<(), String> {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn uninstall_macos() -> Result<(), String> { fn uninstall_macos() -> Result<(), String> {
use std::collections::HashMap;
let path = backup_path(); let path = backup_path();
let json = std::fs::read_to_string(&path) let json = std::fs::read_to_string(&path)
.map_err(|e| format!("no backup found at {}: {}", path.display(), e))?; .map_err(|e| format!("no backup found at {}: {}", path.display(), e))?;