use anyhow::Result;
use std::collections::HashMap;
use std::process::Command;
pub(crate) fn get_ld_cache() -> Result<HashMap<String, String>> {
let output = Command::new("/sbin/ldconfig").arg("-p").output()?;
if !output.status.success() {
anyhow::bail!("ldconfig -p failed with status: {}", output.status);
}
let stdout = String::from_utf8(output.stdout)?;
let mut cache = HashMap::new();
for line in stdout.lines().skip(1) {
let line = line.trim();
if let Some(arrow_pos) = line.find(" => ") {
let lib_name = line[..arrow_pos].trim();
let lib_path = line[arrow_pos + 4..].trim();
if let Some(paren_pos) = lib_name.find(" (") {
let clean_name = &lib_name[..paren_pos];
cache.insert(clean_name.to_string(), lib_path.to_string());
} else {
cache.insert(lib_name.to_string(), lib_path.to_string());
}
}
}
Ok(cache)
}