//! Housekeeping: retention, backups, and clearing the attention list. use std::path::{Path, PathBuf}; use crate::config::Config; use crate::db::{self, Db}; use crate::error::Result; use crate::ops; /// What a garbage collection would do, before anything is deleted. pub struct GcPlan { pub keep: usize, /// Releases whose files survive. pub kept: usize, /// Releases whose files would go, with the files each one owns. pub evicting: Vec<(i64, Vec)>, } /// Work out what retention would remove, without removing it. pub fn plan_gc(cfg: &Config, db: &Db, keep: Option) -> Result { let keep = keep.unwrap_or(ops::DEFAULT_KEEP); let (kept, evict) = ops::plan_retention(db, keep)?; let mut evicting = Vec::with_capacity(evict.len()); for e in evict { evicting.push((e.release_id, ops::release_files(cfg, db, e.release_id)?)); } Ok(GcPlan { keep, kept: kept.len(), evicting }) } /// Delete what retention says should go. pub fn run_gc(cfg: &Config, db: &Db, keep: Option) -> Result { ops::retention(cfg, db, Some(keep.unwrap_or(ops::DEFAULT_KEEP))) } /// Copy the database to a single file, WAL folded in. pub fn backup(db: &Db, dest: &Path) -> Result { ops::backup(db, dest) } /// Mark a notice as seen. pub fn acknowledge_notice(db: &Db, id: i64) -> Result<()> { db::acknowledge_notice(&db.writer, id) }