fix(linux): narrow replace_exe_path cfg to macos after Linux inlined the substitution

Linux install_service_linux now does the {{exe_path}} substitution
inline because it uses the (potentially copied) binary path returned
by install_service_binary_linux, not current_exe(). The shared
replace_exe_path helper is dead on Linux — clippy -D warnings caught it.

Narrow the function to macos and split the placeholder test: keep the
"both templates contain {{exe_path}}" assertion as a cross-platform test
(catches placeholder removal on either file), keep the substitution test
gated to macos where the function lives.
This commit is contained in:
Razvan Dimescu
2026-04-18 11:57:54 +03:00
parent 3970a9f45c
commit e19505aa95

View File

@@ -1416,7 +1416,7 @@ pub fn service_status() -> Result<(), String> {
} }
} }
#[cfg(any(target_os = "macos", target_os = "linux"))] #[cfg(target_os = "macos")]
fn replace_exe_path(service: &str) -> Result<String, String> { fn replace_exe_path(service: &str) -> Result<String, String> {
let exe_path = let exe_path =
std::env::current_exe().map_err(|e| format!("failed to get current exe: {}", e))?; std::env::current_exe().map_err(|e| format!("failed to get current exe: {}", e))?;
@@ -2050,22 +2050,25 @@ Wireless LAN adapter Wi-Fi:
} }
#[test] #[test]
#[cfg(any(target_os = "macos", target_os = "linux"))] fn install_templates_contain_exe_path_placeholder() {
fn replace_exe_path_substitutes_template() { // Both files are substituted at install time — plist via
// replace_exe_path on macOS, numa.service via inline .replace
// in install_service_linux. Catch placeholder removal early.
let plist = include_str!("../com.numa.dns.plist"); let plist = include_str!("../com.numa.dns.plist");
let unit = include_str!("../numa.service"); let unit = include_str!("../numa.service");
assert!(plist.contains("{{exe_path}}"), "plist missing placeholder"); assert!(plist.contains("{{exe_path}}"), "plist missing placeholder");
assert!( assert!(
unit.contains("{{exe_path}}"), unit.contains("{{exe_path}}"),
"unit file missing placeholder" "unit file missing placeholder"
); );
}
#[test]
#[cfg(target_os = "macos")]
fn replace_exe_path_substitutes_template() {
let plist = include_str!("../com.numa.dns.plist");
let result = replace_exe_path(plist).expect("replace_exe_path failed for plist"); let result = replace_exe_path(plist).expect("replace_exe_path failed for plist");
assert!(!result.contains("{{exe_path}}")); assert!(!result.contains("{{exe_path}}"));
let result = replace_exe_path(unit).expect("replace_exe_path failed for unit");
assert!(!result.contains("{{exe_path}}"));
} }
#[test] #[test]