use std::path::PathBuf;
use std::sync::Arc;
use crate::callgraph_store::{ReadonlyCallGraphStore, Result};
use crate::pins::QueryPin;
pub(crate) fn open_published_callgraph(
project_root: PathBuf,
family: String,
view_dir: PathBuf,
generation: &str,
pin: Option<Arc<QueryPin>>,
) -> Result<ReadonlyCallGraphStore> {
ReadonlyCallGraphStore::open_manifest_view(project_root, family, view_dir, generation, pin)
}
pub(crate) fn callgraph_paths_match(
manifest: &super::Manifest,
root: &std::path::Path,
paths: &[PathBuf],
) -> super::Result<bool> {
for path in paths {
let Ok(relative) = path.strip_prefix(root) else {
return Ok(false);
};
let key = super::RelPath::from_os_path(relative)?;
let language = if super::assembly::is_resolution_input(key.as_bytes()) {
Some("config".to_string())
} else {
crate::parser::detect_language(path)
.map(|language| format!("{language:?}").to_lowercase())
};
let Some(language) = language else { continue };
let entry = manifest.get(&key);
let source = match std::fs::read(path) {
Ok(source) => source,
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
if entry.is_some() {
return Ok(false);
}
continue;
}
Err(error) => return Err(error.into()),
};
let Some(entry) = entry else { continue };
if let super::ManifestEntry::Regular { planes, .. } = entry {
let current = crate::blob_store::CallgraphKey::for_current(&source, language)
.full_key()
.to_hex();
if planes.callgraph.as_deref() != Some(current.as_str()) {
return Ok(false);
}
}
}
Ok(true)
}