use crate::db::{self, Db}; use crate::error::Result; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Kind { Outdated, Missing, } /// The real definition. The module is private, so this `pub` /// is not a nameable path from outside; the alias below is the /// only way to reach it, and the alias is what carries the /// feature-conditional visibility. mod stale { use super::*; #[derive(Debug, Clone)] pub struct Stale { pub kind: Kind, pub pkgbase: String, pub dependency: String, pub built_with: String, pub now: String, } } /// one row of the staleness report. `http` and `ops` read the report `stale_rows` returns, but only the staleness tests write the name. /// /// `pub` only under `test-support`. Production reaches the type /// through its own module and never names it from outside; the /// outside reader that needs the name is a test. #[cfg(feature = "test-support")] pub use stale::Stale; #[cfg(not(feature = "test-support"))] pub(crate) use stale::Stale; pub fn stale_rows(db: &Db) -> Result> { let rows = db::published_world_members(db)?; let mut out = Vec::new(); for (pkgbase, members_json) in rows { let members: Vec = serde_json::from_str(&members_json).unwrap_or_default(); for m in members { if m.pkgbase == pkgbase { continue; } match db::index_version(db, &m.pkgbase)? { Some(now) if now != m.version => out.push(Stale { kind: Kind::Outdated, pkgbase: pkgbase.clone(), dependency: m.pkgbase.clone(), built_with: m.version.clone(), now, }), None => out.push(Stale { kind: Kind::Missing, pkgbase: pkgbase.clone(), dependency: m.pkgbase.clone(), built_with: m.version.clone(), now: String::new(), }), Some(_) => {} } } } out.sort_by(|a, b| a.pkgbase.cmp(&b.pkgbase).then(a.dependency.cmp(&b.dependency))); Ok(out) } pub fn stale_for(db: &Db, pkgbase: &str) -> Result> { Ok(stale_rows(db)?.into_iter().filter(|s| s.pkgbase == pkgbase).collect()) } pub fn downgrades(db: &Db) -> Result> { let rows = db::served_vs_offered_pkgvers(db)?; let mut out = Vec::new(); for (pkgbase, served, offered) in rows { if offered.is_empty() || !crate::pkgver::is_downgrade(&served, &offered) { continue; } out.push(Stale { kind: Kind::Outdated, pkgbase: pkgbase.clone(), dependency: "aur".into(), built_with: served, now: offered, }); } Ok(out) } pub fn dependents_of(db: &Db, name: &str) -> Result> { let mut out: Vec = Vec::new(); for (pkgname, json) in db::index_recipes(db)? { if pkgname == name { continue; } let depends = match serde_json::from_str::(&json) { Ok(r) => crate::pkgver::dep_names(&r.depends) .into_iter() .any(|d| d == name), Err(_) => true, }; if depends { out.push(pkgname); } } Ok(out) }