//! Checking whether an upstream moved — one pkgbase, or every active one. use crate::config::Config; use crate::db::{self, Db, SubscriptionState}; use crate::error::Result; use crate::watch::detect::{self, Outcome}; /// One pkgbase's detection result. /// /// Per-item failures are returned rather than raised: a sweep over every /// subscription should not stop at the first pkgbase whose mirror is /// unreachable, and the caller decides whether a failure is a line on stderr /// or a row in a table. pub struct Checked { pub pkgbase: String, pub outcome: Result, } /// Detect one pkgbase, or every active subscription if none was named. pub fn detect(cfg: &Config, db: &Db, pkgbase: Option) -> Result> { let names: Vec = match pkgbase { Some(n) => vec![n], None => db::list_subscriptions(db)? .into_iter() .filter(|s| s.state == SubscriptionState::Active) .map(|s| s.pkgbase) .collect(), }; Ok(names .into_iter() .map(|n| { let outcome = check(cfg, db, &n); Checked { pkgbase: n, outcome } }) .collect()) } /// Detect a single pkgbase and discard the report beyond its outcome. pub fn check(cfg: &Config, db: &Db, pkgbase: &str) -> Result { detect::check_pkgbase(cfg, db, pkgbase).map(|r| r.outcome) }