summaryrefslogtreecommitdiffstats
path: root/src/watch/detect.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/watch/detect.rs')
-rw-r--r--src/watch/detect.rs82
1 files changed, 24 insertions, 58 deletions
diff --git a/src/watch/detect.rs b/src/watch/detect.rs
index 6271dae..de1285e 100644
--- a/src/watch/detect.rs
+++ b/src/watch/detect.rs
@@ -1,11 +1,3 @@
-//! Detection: the recipe watcher pass for one pkgbase (§5.1, §5.2, §5.3).
-//!
-//! The decision that matters is *what counts as a change*. A candidate exists
-//! only if something **publishable** changed — if the version string is
-//! unchanged, `pacman` cannot offer an upgrade, so there is nothing to approve.
-//! Those events become `notice` rows instead, and are never silently dropped
-//! (I11).
-
use crate::config::Config;
use crate::db::{self, *};
use crate::error::Result;
@@ -18,19 +10,10 @@ use crate::watch::mirror::{read_tree, sync_mirror, Sync};
/// What one check of one pkgbase resulted in.
///
-/// Four variants mirror [`Upsert`], and that is deliberate rather than lazy
-/// duplication (n-2). `Upsert` answers a storage question — what did the
-/// candidate write do — and belongs to `review::candidates`; `Outcome` answers
-/// the watcher's question — what should happen next, including the cases that
-/// never reach the candidate table at all (paused, gone, blocked, a
-/// non-publishable notice). Folding them into one enum would put
-/// `Paused`/`Blocked` next to `Collapsed` in the review module, where they mean
-/// nothing, and would make every caller in the scheduler match on storage
-/// vocabulary. `outcome_of` is the total, compiler-checked translation between
-/// the two, and it is the only place that knows both.
+/// Four variants mirror [`Upsert`] deliberately (n-2): `Upsert` answers the storage
+/// question, `Outcome` the watcher's. `outcome_of` is the only place that knows both.
#[derive(Debug, Clone)]
pub enum Outcome {
- /// Nothing moved at all.
NoChange,
/// The subscription is paused: we look at nothing and change nothing.
Paused,
@@ -61,11 +44,9 @@ pub struct CheckReport {
pub fn check_pkgbase(cfg: &Config, db: &Db, name: &str) -> Result<CheckReport> {
let pb = get_pkgbase(db, name)?
.ok_or_else(|| crate::error::Error::not_found(format!("pkgbase {name}")))?;
- // A paused subscription is not observed at all. Pausing because a package is
- // broken must not keep opening reviews nobody is going to act on, and it
- // must not keep polling AUR either. The pause lives on the subscription, so
- // that is what we consult.
- let sub = db::get_subscription(db, name)?;
+ // A paused subscription is not observed at all: pausing must not keep opening
+ // reviews nobody will act on, nor keep polling AUR.
+ let sub = db::get_subscription(db, name)?;;
let paused = sub.as_ref().map(|s| s.state == SubscriptionState::Paused).unwrap_or(false);
if paused {
return Ok(CheckReport { pkgbase: name.into(), head: String::new(), outcome: Outcome::Paused });
@@ -83,9 +64,8 @@ pub fn check_pkgbase(cfg: &Config, db: &Db, name: &str) -> Result<CheckReport> {
db::set_subscription_state(&db.writer, name, SubscriptionState::Orphaned)?;
return Ok(CheckReport { pkgbase: name.into(), head: String::new(), outcome: Outcome::Gone });
}
- // The cheap poll saved us a fetch, but we still have to look: a source
- // can change its bytes without the recipe moving at all, and that is the
- // digest-drift case §5.3 calls the single most valuable detection.
+ // The cheap poll saved a fetch, but we still have to look: a source can
+ // change its bytes without the recipe moving (§5.3).
Sync::Unchanged { head } => head.clone(),
Sync::Fetched { head, .. } | Sync::Cloned { head } => head.clone(),
};
@@ -95,18 +75,13 @@ pub fn check_pkgbase(cfg: &Config, db: &Db, name: &str) -> Result<CheckReport> {
}
/// When to look at this pkgbase again: its own interval if the subscription
-/// carries one, otherwise the global default.
-///
-/// The interval arrives as an argument because the caller read the subscription
-/// row a moment ago to decide whether this pkgbase is paused (m-11); going back
-/// to the database for a number the caller was holding was both a second query
-/// and a second, possibly different, answer.
+/// carries one, otherwise the global default. The interval is an argument because
+/// the caller already read the subscription row (m-11).
fn schedule_next(db: &Db, name: &str, poll_interval: Option<i64>) {
let interval = poll_interval.unwrap_or_else(|| crate::db::setting_i64(db, "poll_interval", 86400));
let next = time::secs_ahead(interval);
- // Best-effort: a missed "next check" stamp means the scheduler looks again
- // a tick early, not that a change goes unnoticed — the tick re-selects by
- // `next_check_at` and a NULL is due immediately.
+ // Best-effort: a missed stamp means the scheduler looks again a tick early,
+ // not that a change goes unnoticed.
let _ = db::note_check(&db.writer, name, &next, None);
}
@@ -139,12 +114,11 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result<CheckRepor
let recipe_hash = tree.recipe_hash();
// §5.2, the two-stage funnel. Stage A is one `ls-remote` per VCS source and
- // costs no clone; if the tip set is what the accepted release was built
- // from, nothing can have changed and Stage B never runs.
+ // costs no clone; if the tip set is what the accepted release was built from,
+ // nothing can have changed and Stage B never runs.
let has_vcs = recipe.source_entries.iter().any(|e| e.is_vcs());
let accepted_pins: Vec<UpstreamPin> = accepted.as_ref().map(|a| a.pins()).unwrap_or_default();
- // A recipe with no VCS sources states its own version; there is nothing to
- // probe and nothing to resolve.
+ // A recipe with no VCS sources states its own version.
let stage_a = if has_vcs {
Some(crate::watch::upstream::probe(&recipe, &accepted_pins)?)
} else {
@@ -155,8 +129,8 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result<CheckRepor
} else if stage_a.as_ref().unwrap().needs_stage_b() {
crate::watch::upstream::resolve(cfg, db, pb, &recipe, &recipe_hash, stage_a.as_ref().unwrap())?
} else {
- // Upstream has not moved. The version we serve is still the answer, and
- // reusing its pins is what makes the next pass cheap too.
+ // Upstream has not moved; reusing the accepted pins keeps the next pass
+ // cheap too.
accepted.as_ref().map(|a| crate::watch::upstream::StageB {
epoch: a.epoch.clone(),
pkgver: a.pkgver.clone(),
@@ -166,7 +140,7 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result<CheckRepor
})
};
// For a VCS package the literal `pkgver=` is frozen; the resolved one is the
- // only version a consumer could actually install.
+ // only version a consumer could install.
let (epoch, pkgver, pkgrel, pins) = match &resolved {
Some(r) => (r.epoch.clone(), r.pkgver.clone(), r.pkgrel.clone(), r.pins.clone()),
None => (recipe.epoch.clone(), recipe.pkgver.clone(), recipe.pkgrel.clone(), Vec::new()),
@@ -266,9 +240,7 @@ fn score(
let _ = crate::review::candidates::set_risk(db, id, &a.level, &a.signals);
}
// Record now what would block the build later, using the same rule the plan
- // step uses. A reviewer approving a package whose dependencies we have not
- // published yet should see that before they approve it, not as a blocked
- // build afterwards (§10.4).
+ // step uses, so a reviewer sees it before approving (§10.4).
let missing = missing_deps(db, pb, recipe);
let _ = crate::review::candidates::set_missing_deps(db, id, &missing);
}
@@ -306,9 +278,8 @@ fn outcome_of(up: Upsert) -> Outcome {
}
}
-/// The version string did not move, so there is no review to open — but the
-/// change is recorded, because a silently drifting tarball is exactly the kind
-/// of thing that must not be invisible (§5.3).
+/// The version string did not move, so there is no review to open — but the change
+/// is recorded, because a silently drifting tarball must not be invisible (§5.3).
fn non_publishable(
db: &Db,
pb: &Pkgbase,
@@ -319,12 +290,8 @@ fn non_publishable(
let old_digests: Vec<SourceDigest> = base.digests();
let new_digests: Vec<SourceDigest> = serde_json::from_str(&nc.source_digests_json).unwrap_or_default();
// A local source is part of the recipe: when its bytes move, that *is* the
- // recipe drift, not an integrity event. The integrity alert is specifically
- // "the bytes upstream serves no longer match what we built" (§5.3).
- // A VCS source's digest *is* its pin, so upstream moving shows up there too
- // — but that is ordinary drift, handled by the pin check below, not an
- // integrity event. Integrity means "the bytes we built are gone and the
- // version says nothing moved", which only applies to fixed downloads.
+ // recipe drift. A VCS source's digest is its pin, so upstream moving shows up
+ // there too, but that is ordinary drift (§5.3).
let vcs_indices: std::collections::BTreeSet<usize> = recipe
.source_entries
.iter()
@@ -346,9 +313,8 @@ fn non_publishable(
if digest_changed {
// The single most valuable detection in the system: the artifact in the
- // index was built from bytes upstream no longer serves, and the version
- // string is unchanged. An approval would be useless (approving it would
- // not let us publish anything), so this is an alert, not a review.
+ // index was built from bytes upstream no longer serves, and the version is
+ // unchanged. An approval would be useless, so this is an alert.
let changed: Vec<serde_json::Value> = changed_remote
.iter()
.map(|n| {