diff options
| author | aur-build <aur-build@localhost> | 2026-11-19 17:09:59 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-19 17:09:59 +0000 |
| commit | e757979f1a2afdbe7146066345bb9acd19d3b151 (patch) | |
| tree | 30d5f5fbccd25ea7bf01c5202684af463b74e7d3 /src/watch | |
| parent | 94c318f13264bb3c00a9f3057ba2e1aafb57c9e4 (diff) | |
| download | aur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.tar.gz aur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.zip | |
comments: say why, not what
Every module-level `//!` header is gone, and the comments that remained
either re-explained the line below them or had grown into paragraphs.
Density went from one comment line per 6.7 lines of code to one per 10.
827 insertions against 2194 deletions across 86 files.
What survived: the invariants (I1-I12), the design cross-references into
DESIGN.md, and the notes recording a bug that was found and fixed — those
are the comments that carry weight, because they answer a question the
code cannot answer about itself. What did not: restating a function
signature in prose, and narration of the statement underneath.
Diffstat (limited to 'src/watch')
| -rw-r--r-- | src/watch/detect.rs | 82 | ||||
| -rw-r--r-- | src/watch/digests.rs | 26 | ||||
| -rw-r--r-- | src/watch/mirror.rs | 14 | ||||
| -rw-r--r-- | src/watch/mod.rs | 3 | ||||
| -rw-r--r-- | src/watch/scheduler.rs | 5 | ||||
| -rw-r--r-- | src/watch/staleness.rs | 19 | ||||
| -rw-r--r-- | src/watch/upstream.rs | 28 |
7 files changed, 40 insertions, 137 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| { diff --git a/src/watch/digests.rs b/src/watch/digests.rs index 8136850..d3119eb 100644 --- a/src/watch/digests.rs +++ b/src/watch/digests.rs @@ -1,15 +1,3 @@ -//! Source digest resolution (§5.3). -//! -//! `sha256sums=('SKIP')` is the hole in the integrity story. We resolve and -//! record the digest of *every* source ourselves, at detection time, regardless -//! of what the PKGBUILD declares — which turns a silent artifact swap into a -//! reviewable (or at least alertable) event. -//! -//! Cost control: only `SKIP`-declared static sources cost bandwidth. Declared -//! checksums are trusted-as-declared for identity because makepkg enforces them -//! at build time; VCS digests come free from the pin we already resolved; local -//! files are already in the mirror. - use crate::config::Config; use crate::db::{self, *}; use crate::error::Result; @@ -49,10 +37,9 @@ pub fn resolve_sources( digest, size: 0, // Computed from the recipe like every other entry (m-19), not - // hardcoded: the field answers "did the recipe give us a - // checksum?", and for a VCS source the answer is usually yes-by- - // absence — which is why renderers must ask `is_vcs` before - // calling it a missing checksum. + // hardcoded: for a VCS source the answer is usually + // yes-by-absence, so renderers must ask `is_vcs` before calling + // it a missing checksum. skip_declared: match declared_sums(recipe, entry.index) { Some(d) => d == SKIP || !is_hex_digest(&d), None => true, @@ -120,11 +107,8 @@ pub fn resolve_sources( /// Download `url`, hashing as we go, and record it in `source_cache`. /// -/// This always goes to the network. That is deliberate: the whole point of §5.3 -/// is to notice that the bytes behind a `SKIP` source changed while the version -/// did not, and answering from our own cache would make that impossible. The -/// cache exists so the *build* can reuse the bytes it was reviewed against -/// ([`cached_path`]), not so detection can skip looking. +/// This always goes to the network: the point of .5.3 is to notice that the bytes +/// behind a `SKIP` source changed while the version did not. pub fn download_and_cache(cfg: &Config, db: &Db, url: &str) -> Result<(String, u64)> { let tmp = cfg.source_cache_dir().join(format!("tmp-{}", crate::hash::short(url.as_bytes(), 16))); let (digest, size) = crate::fetch::fetch_to(url, &tmp)?; diff --git a/src/watch/mirror.rs b/src/watch/mirror.rs index 989b968..b6f9c47 100644 --- a/src/watch/mirror.rs +++ b/src/watch/mirror.rs @@ -1,10 +1,3 @@ -//! The local AUR git mirror (§5.1). -//! -//! Clone, don't scrape. The mirror is load-bearing rather than a cache: every -//! build materializes its recipe from it at the pinned commit and never asks -//! the network for a recipe (§5.1a), so losing it would mean losing the ability -//! to reproduce any historical release. - use std::collections::BTreeMap; use std::path::Path; @@ -64,11 +57,10 @@ fn record(db: &Db, name: &str, head: &str, mirror: &Path) -> Result<()> { #[derive(Debug, Clone)] pub struct Tree { /// `(path, git blob id)` for every file in the tree — the input to - /// `recipe_hash`. Covers PKGBUILD, .SRCINFO, *.install and shipped patches - /// (§3): a patch file is part of the recipe. + /// `recipe_hash`, which covers shipped patches too (§3). pub blobs: Vec<(String, String)>, - /// Text bodies, keyed by path. Binary files are omitted from this map but - /// still counted in `blobs`. + /// Text bodies, keyed by path. Binary files are omitted here but still + /// counted in `blobs`. pub files: BTreeMap<String, String>, } diff --git a/src/watch/mod.rs b/src/watch/mod.rs index 87df3f3..8c7604f 100644 --- a/src/watch/mod.rs +++ b/src/watch/mod.rs @@ -1,6 +1,3 @@ -//! Watchers: AUR recipe mirror (§5.1), upstream VCS probe (§5.2), source digest -//! resolution (§5.3), and the scheduler tick. - pub mod detect; pub mod digests; pub mod mirror; diff --git a/src/watch/scheduler.rs b/src/watch/scheduler.rs index ca42e32..837a51a 100644 --- a/src/watch/scheduler.rs +++ b/src/watch/scheduler.rs @@ -1,8 +1,3 @@ -//! The scheduler tick (§4: "one tick thread + sweep over `next_check_at`"). -//! -//! Blocking is the right shape here: the tick sleeps between sweeps and each -//! sweep is a sequence of blocking git and HTTP calls. - use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::thread::JoinHandle; diff --git a/src/watch/staleness.rs b/src/watch/staleness.rs index e052b26..2631769 100644 --- a/src/watch/staleness.rs +++ b/src/watch/staleness.rs @@ -1,14 +1,3 @@ -//! Staleness (§10.2): "would rebuilding this change what a consumer gets?" -//! -//! Computed **on read**, never stored. A stored staleness flag goes wrong the -//! moment anything else is published, and there is always something else being -//! published; deriving it from the world snapshots and the current index means -//! it can never lie. -//! -//! The pair comes from §10.1: each build recorded the versions of *our* -//! packages it was built against. If any of those differ from what the index -//! holds now, the artifact was built against a world that no longer exists. - use crate::db::{self, Db}; use crate::error::Result; @@ -73,12 +62,10 @@ pub fn stale_for(db: &Db, pkgbase: &str) -> Result<Vec<Stale>> { Ok(stale_rows(db)?.into_iter().filter(|s| s.pkgbase == pkgbase).collect()) } -/// AUR now offers a **lower** version than we serve (§10.2). This is not a -/// build request; it is an announcement that the mirror and the upstream have -/// disagreed, and someone has to decide which one consumers follow. +/// AUR now offers a **lower** version than we serve (§10.2). This is not a build +/// request; it is an announcement that the mirror and upstream have disagreed. /// -/// Derived on read from the newest candidate per pkgbase against the accepted -/// release, so it disappears the moment either side moves. +/// Derived on read, so it disappears the moment either side moves. pub fn downgrades(db: &Db) -> Result<Vec<Stale>> { let rows = db::served_vs_offered_pkgvers(db)?; let mut out = Vec::new(); diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs index c2772a2..507d734 100644 --- a/src/watch/upstream.rs +++ b/src/watch/upstream.rs @@ -1,20 +1,3 @@ -//! The two-stage VCS watcher (§5.2) — the expensive path, made cheap. -//! -//! For a `-git` package the `pkgver=` field is frozen and the real version is -//! computed by `pkgver()` at build time, so detection cannot read it off the -//! recipe. Running the real thing every poll would be absurd, so: -//! -//! **Stage A** asks each upstream where its tip is now (`git ls-remote`, which -//! costs one network round trip and no clone). If the set of tips is identical -//! to the set recorded on the accepted release, *nothing can have changed* and -//! we stop. This is the common case: most days, nothing moves. -//! -//! **Stage B** runs only when Stage A saw movement: clone/fetch into the -//! persistent cache, run `makepkg --vercheck` against the recipe, and read back -//! the computed `epoch:pkgver-pkgrel` — the only correct answer, because -//! `pkgver()` can do arbitrary things. The clone is already there, so this is -//! also where the pins are captured. - use std::collections::BTreeSet; use std::path::PathBuf; use std::process::Command; @@ -148,9 +131,8 @@ impl StageB { } } -/// A process-wide cap on concurrent Stage B resolutions (§5.2 "a global -/// concurrency cap"). Each one clones repositories and runs a chroot-less -/// makepkg; letting twenty run at once would be silly. +/// A process-wide cap on concurrent Stage B resolutions (§5.2). Each one clones +/// repositories and runs a chroot-less makepkg. static RUNNING: AtomicUsize = AtomicUsize::new(0); static SLOT_FREE: Condvar = Condvar::new(); static SLOT_LOCK: Mutex<()> = Mutex::new(()); @@ -205,9 +187,9 @@ pub fn resolve( return Ok(Some(StageB::from_cache(hit))); } - // Per-pkgbase cooldown: even if the tips moved again, we do not re-resolve - // the same pkgbase more than once per cooldown window. The previous answer - // is reused, so a chatty upstream cannot turn detection into a build loop. + // Per-pkgbase cooldown: even if the tips moved again, we do not re-resolve the + // same pkgbase more than once per window, so a chatty upstream cannot turn + // detection into a build loop. let cooldown = db::setting_i64(db, "stage_b_cooldown", 86400); if let Some(recent) = db::stage_b_recent(db, pb.id, cooldown)? { return Ok(Some(StageB::from_cache(recent))); |
