summaryrefslogtreecommitdiffstats
path: root/src/usecase/detect.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/usecase/detect.rs')
-rw-r--r--src/usecase/detect.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/usecase/detect.rs b/src/usecase/detect.rs
new file mode 100644
index 0000000..67cc83c
--- /dev/null
+++ b/src/usecase/detect.rs
@@ -0,0 +1,41 @@
+//! 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<Outcome>,
+}
+
+/// Detect one pkgbase, or every active subscription if none was named.
+pub fn detect(cfg: &Config, db: &Db, pkgbase: Option<String>) -> Result<Vec<Checked>> {
+ let names: Vec<String> = 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<Outcome> {
+ detect::check_pkgbase(cfg, db, pkgbase).map(|r| r.outcome)
+}