From f586d11f6a1711145ba4804787217a1bab58751d Mon Sep 17 00:00:00 2001 From: aur-build Date: Tue, 17 Nov 2026 21:19:35 +0000 Subject: feat: AUR mirror watcher, recipe parsing, candidate creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The detection path (§5.1, §5.1a, §5.3, §7.1): * git helpers, all subprocess git in one auditable place. Mirrors are cloned with --mirror and polled with git ls-remote, fetching only when the tip actually moved; --no-prune keeps history we may need forever. * .SRCINFO parsing (authoritative) with a PKGBUILD fallback, and source=() parsing that keeps VCS kind, #commit/#tag/#branch refs and the filename:: form. * recipe_hash over the whole snapshot tree, so a shipped patch is part of the recipe and cannot change silently. * source digest resolution: declared checksums are trusted-as-declared (makepkg enforces them, no bandwidth), local files are hashed from the mirror, and SKIP sources are downloaded and stream-hashed into the content-addressed source cache. Detection always re-fetches SKIP sources — answering from our own cache would defeat drift detection. * candidate creation with base = current_accepted_release, collapse in place while unviewed, supersede only once a human has looked, and a previously rejected identity is not re-raised. * non-publishable change handling (I11): unchanged version string means no review, but never silence — recipe drift and pin drift become notices, and a changed digest on a remote source with an unchanged version becomes a high-severity integrity_alert. Also vercmp + dep-string parsing with the ALPM test vectors, and the approval record with optimistic concurrency (§7.1a) that the CLI and web layers will both call. 16 detection tests against real file:// git fixtures, incl. I2 across three unattended detections and I11 for all three drift kinds. Part of P0 (DESIGN.md §17). --- src/watch/scheduler.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/watch/scheduler.rs (limited to 'src/watch/scheduler.rs') diff --git a/src/watch/scheduler.rs b/src/watch/scheduler.rs new file mode 100644 index 0000000..ca42e32 --- /dev/null +++ b/src/watch/scheduler.rs @@ -0,0 +1,71 @@ +//! 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; + +use crate::config::Config; +use crate::db::{self, Db}; +use crate::watch::detect::check_pkgbase; + +/// Spawn the watcher tick thread. +pub fn spawn_scheduler(cfg: Arc, db: Db, stop: Arc) -> JoinHandle<()> { + std::thread::Builder::new() + .name("watcher".into()) + .spawn(move || { + while !stop.load(Ordering::SeqCst) { + let tick = crate::db::setting_i64(&db, "poll_tick", 30); + sweep(&cfg, &db); + // Sleep in small slices so shutdown is prompt. + let mut slept = 0; + while slept < tick && !stop.load(Ordering::SeqCst) { + std::thread::sleep(std::time::Duration::from_secs(1)); + slept += 1; + } + } + }) + .expect("spawn watcher") +} + +/// One sweep over everything that is due. +pub fn sweep(cfg: &Config, db: &Db) -> usize { + let now = crate::time::now(); + let due = match db::due_subscriptions(db, &now) { + Ok(d) => d, + Err(_) => return 0, + }; + let mut n = 0; + for sub in due { + // Mark it checked first so a slow or hanging source cannot make the + // scheduler re-enter it on the next tick. + let interval = sub + .poll_interval_secs + .unwrap_or(crate::db::setting_i64(db, "poll_interval", 86400)); + let _ = db::note_check(&db.writer, &sub.pkgbase, &crate::time::secs_ahead(interval), None); + match check_pkgbase(cfg, db, &sub.pkgbase) { + Ok(report) => { + if matches!(report.outcome, crate::watch::detect::Outcome::Blocked(_)) { + let _ = db::note_check( + &db.writer, + &sub.pkgbase, + &crate::time::secs_ahead(600), + Some(&format!("{:?}", report.outcome)), + ); + } + } + Err(e) => { + let _ = db::note_check( + &db.writer, + &sub.pkgbase, + &crate::time::secs_ahead(600), + Some(&e.to_string()), + ); + } + } + n += 1; + } + n +} -- cgit v1.2.3