pub(crate) fn prior_index_count_path() -> Option<std::path::PathBuf> {
crate::service::daemon::daemon_lock_path()
.ok()
.and_then(|p| p.parent().map(|d| d.join("prior_index_count.txt")))
}
pub(crate) fn save_prior_index_count(count: usize) {
let Some(path) = prior_index_count_path() else {
return;
};
let content = format!("{count}\n");
if let Err(e) = std::fs::write(&path, content) {
tracing::debug!(
"warm-boot: could not save prior index count to {}: {e}",
path.display()
);
}
}
pub(crate) fn load_prior_index_count() -> usize {
let Some(path) = prior_index_count_path() else {
return 0;
};
std::fs::read_to_string(&path)
.ok()
.and_then(|s| s.trim().parse::<usize>().ok())
.unwrap_or(0)
}
pub(crate) fn record_warm_boot_result(
state: &crate::service::SearchAppState,
total: usize,
total_skipped_tcc: usize,
total_skipped_timeout: usize,
) {
let prior_count = state
.prior_index_count
.load(std::sync::atomic::Ordering::Relaxed);
let degraded_by_tcc = total_skipped_tcc > 0;
let degraded_by_count = prior_count > 0 && total < prior_count * 4 / 5;
let warm_boot_degraded = degraded_by_tcc || degraded_by_count;
if let Ok(mut summary) = state.warmboot_summary.lock() {
*summary = crate::service::server::WarmBootSummary {
indexes_loaded: total,
indexes_skipped_tcc: total_skipped_tcc,
indexes_skipped_timeout: total_skipped_timeout,
warm_boot_degraded,
};
}
if degraded_by_count {
tracing::error!(
loaded = total,
prior = prior_count,
skipped_tcc = total_skipped_tcc,
"warm-boot DEGRADED: only {total}/{prior_count} indexes loaded (< 80% of prior). \
If you just ran `cargo install trusty-search`, macOS TCC likely revoked \
Full Disk Access because the new binary has a different cdhash. \
ACTION REQUIRED: re-grant Full Disk Access in \
System Settings → Privacy & Security → Full Disk Access → \
remove and re-add ~/.cargo/bin/trusty-search. \
This is NOT data loss — all on-disk indexes are intact. (issue #873)"
);
}
if total > 0 {
save_prior_index_count(total);
state
.prior_index_count
.store(total, std::sync::atomic::Ordering::Relaxed);
}
}