diff options
Diffstat (limited to 'src/usecase/maintenance.rs')
| -rw-r--r-- | src/usecase/maintenance.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/usecase/maintenance.rs b/src/usecase/maintenance.rs new file mode 100644 index 0000000..4276016 --- /dev/null +++ b/src/usecase/maintenance.rs @@ -0,0 +1,43 @@ +//! 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<PathBuf>)>, +} + +/// Work out what retention would remove, without removing it. +pub fn plan_gc(cfg: &Config, db: &Db, keep: Option<usize>) -> Result<GcPlan> { + 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<usize>) -> Result<ops::RetentionReport> { + 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<PathBuf> { + ops::backup(db, dest) +} + +/// Mark a notice as seen. +pub fn acknowledge_notice(db: &Db, id: i64) -> Result<()> { + db::acknowledge_notice(&db.writer, id) +} |
