use crate::commands::reindex_engine::RegisterFilters;
use crate::config::{CollectionConfig, GlobalConfig};
pub(super) fn persist_collection_to_global_config(
index_name: &str,
project_path: &std::path::Path,
filters: &RegisterFilters,
) {
let mut cfg = match GlobalConfig::load() {
Ok(c) => c,
Err(e) => {
tracing::warn!("could not load global config to record index '{index_name}': {e:#}");
return;
}
};
cfg.upsert_collection(CollectionConfig {
name: index_name.to_string(),
path: project_path.to_path_buf(),
extensions: filters.extensions.clone(),
exclude: filters.exclude_globs.clone(),
domain_terms: filters.domain_terms.clone(),
});
if let Err(e) = cfg.save() {
tracing::warn!("could not save global config after registering '{index_name}': {e:#}");
}
if crate::allowlist::is_denied(project_path).is_none() {
let entry = crate::allowlist::AllowlistEntry {
path: project_path.to_path_buf(),
name: Some(index_name.to_string()),
exclude: filters.exclude_globs.clone(),
extensions: filters.extensions.clone(),
skip_kg: filters.skip_kg,
};
if let Err(e) = crate::allowlist::add_to_allowlist(entry, None) {
tracing::warn!("could not write allowlist entry for '{index_name}': {e:#}");
}
}
}