summaryrefslogtreecommitdiffstats
path: root/src/watch
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 08:06:39 +0000
committeraur-build <aur-build@localhost>2026-11-18 08:06:39 +0000
commita6b652985f40cf022d6c522415c36fad13bc663d (patch)
tree2383d83a820803808202084db1aa30b12f0e02c2 /src/watch
parentab8d33d5edc4c88075685206e3046c719e9bc855 (diff)
downloadaur-build-a6b652985f40cf022d6c522415c36fad13bc663d.tar.gz
aur-build-a6b652985f40cf022d6c522415c36fad13bc663d.zip
http: the review surface — server-rendered, no JavaScript required (§12, §13)
tiny_http, thread-per-connection, askama templates. Every §13 surface is server-rendered HTML that works with scripts switched off: Inbox, review detail with the full panel set, Builds, Attention, Index, Subscriptions, Ops/audit, Settings. The parts that are easy to get wrong: - Handlers read through thread-local READ-ONLY connections. They cannot take the write lock even by accident, so a slow page render never blocks the build pipeline's writer. tests/http.rs asserts this by trying to write through a read connection and requiring failure. - Every POST requires a CSRF token derived from the session id. Logout drops the session, which invalidates every form still open in a browser. - Approve carries identity_hash AND diff_digest (§7.1a). If either has moved, the approval is refused with 409 and the page re-renders the review AS IT IS NOW — never a silent retarget onto the newer state. - Bulk approve refuses high-risk items unless each one is individually confirmed by id. Bulk is per-item, never 'approve everything forever'. - Reject requires a note; it is re-openable, not a deletion. - Optional password gate; anonymous visitors are redirected to /login. Also: the index page states the pacman conf snippet including 'SigLevel = Required DatabaseOptional', because a repo consumers ignore the signature is a repo that gets MITM'd.
Diffstat (limited to 'src/watch')
-rw-r--r--src/watch/mod.rs1
-rw-r--r--src/watch/staleness.rs125
2 files changed, 126 insertions, 0 deletions
diff --git a/src/watch/mod.rs b/src/watch/mod.rs
index 2016166..f469f86 100644
--- a/src/watch/mod.rs
+++ b/src/watch/mod.rs
@@ -5,6 +5,7 @@ pub mod detect;
pub mod digests;
pub mod mirror;
pub mod scheduler;
+pub mod staleness;
pub mod upstream;
pub use detect::{check_pkgbase, CheckReport, Outcome};
diff --git a/src/watch/staleness.rs b/src/watch/staleness.rs
new file mode 100644
index 0000000..40bafeb
--- /dev/null
+++ b/src/watch/staleness.rs
@@ -0,0 +1,125 @@
+//! 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;
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum Kind {
+ /// A dependency we publish has moved on.
+ Outdated,
+ /// A dependency we publish has disappeared from the index.
+ Missing,
+}
+
+#[derive(Debug, Clone)]
+pub struct Stale {
+ pub kind: Kind,
+ /// The pkgbase that would need rebuilding.
+ pub pkgbase: String,
+ /// The dependency, or the pkgbase itself for `Missing`.
+ pub dependency: String,
+ /// Version it was built against.
+ pub built_with: String,
+ /// Version the index serves now (empty when missing).
+ pub now: String,
+}
+
+/// Every stale package, derived from world snapshots against the live index.
+pub fn stale_rows(db: &Db) -> Result<Vec<Stale>> {
+ let rows: Vec<(String, String, String, String)> = db.read(|c| {
+ let mut st = c.prepare(
+ "SELECT p.name, w.members_json
+ FROM release r
+ JOIN pkgbase p ON p.id = r.pkgbase_id
+ JOIN build b ON b.id = r.build_id
+ JOIN world_snapshot w ON w.id = b.world_snapshot_id
+ WHERE r.state = 'published'",
+ )?;
+ let rows = st.query_map([], |r| {
+ Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?, String::new(), String::new()))
+ })?;
+ Ok(rows.filter_map(|r| r.ok()).collect::<Vec<_>>())
+ })?;
+
+ let mut out = Vec::new();
+ for (pkgbase, members_json, _, _) in rows {
+ let members: Vec<db::WorldMember> = serde_json::from_str(&members_json).unwrap_or_default();
+ for m in members {
+ // A package is not stale relative to itself.
+ 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)
+}
+
+/// Staleness for one pkgbase, rendered for the package page.
+pub fn stale_for(db: &Db, pkgbase: &str) -> Result<Vec<Stale>> {
+ Ok(stale_rows(db)?.into_iter().filter(|s| s.pkgbase == pkgbase).collect())
+}
+
+/// "If I approve this, what goes stale?" — the dependents question (§10.3).
+/// A package depends on `name` if `name` appears in its recorded world or in
+/// its recipe dependencies.
+pub fn dependents_of(db: &Db, name: &str) -> Result<Vec<String>> {
+ let mut out: Vec<String> = Vec::new();
+ for p in db::index_packages(db)? {
+ if p.name == name {
+ continue;
+ }
+ let depends: bool = db.read(|c| {
+ use rusqlite::OptionalExtension;
+ let json: Option<String> = c
+ .query_row(
+ "SELECT s.srcinfo_json FROM package pk
+ JOIN release r ON r.id = pk.release_id
+ JOIN candidate cnd ON cnd.id = r.candidate_id
+ JOIN snapshot s ON s.id = cnd.snapshot_id
+ WHERE pk.name = ?1 AND pk.state='in_index'",
+ rusqlite::params![p.name],
+ |r| r.get::<_, String>(0),
+ )
+ .optional()?;
+ Ok(json
+ .and_then(|j| serde_json::from_str::<crate::db::model::Recipe>(&j).ok())
+ .map(|r| {
+ crate::pkgver::dep_names(&r.depends)
+ .into_iter()
+ .any(|d| d == name)
+ })
+ .unwrap_or(false))
+ })?;
+ if depends {
+ out.push(p.name);
+ }
+ }
+ Ok(out)
+}