diff options
| author | aur-build <aur-build@localhost> | 2026-11-19 17:33:17 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-19 17:33:17 +0000 |
| commit | 4304b0f336ddba7b4ec6780795059ff2066d105b (patch) | |
| tree | 10edea744a1c2bf3fc363b4dc7f64abac8b1a0d3 /src/pipeline | |
| parent | e757979f1a2afdbe7146066345bb9acd19d3b151 (diff) | |
| download | aur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.tar.gz aur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.zip | |
comments: keep only what the code cannot show
Stripped every comment that described what an item does, documented its
arguments or fields, or cited the design docs (§n, I-n, m-n, decision n).
2247 comments down to 83.
What survives: the section dividers that segment the large modules, the
secret-handling warnings, the agent wire-frame directions, and the few notes
without which the code they attach to reads as redundant, reorderable, or
unsound.
Diffstat (limited to 'src/pipeline')
| -rw-r--r-- | src/pipeline/dispatch.rs | 25 | ||||
| -rw-r--r-- | src/pipeline/mod.rs | 41 | ||||
| -rw-r--r-- | src/pipeline/publish.rs | 61 | ||||
| -rw-r--r-- | src/pipeline/steps.rs | 73 |
4 files changed, 4 insertions, 196 deletions
diff --git a/src/pipeline/dispatch.rs b/src/pipeline/dispatch.rs index d9891c2..88f300e 100644 --- a/src/pipeline/dispatch.rs +++ b/src/pipeline/dispatch.rs @@ -8,21 +8,15 @@ use crate::config::Config; use crate::db::{self, builds, Db}; use crate::pipeline::{self, Outcome}; -/// Handle on a running pool. Dropping without `shutdown` leaves the threads -/// running; call `shutdown` to join them cleanly. pub struct Pool { stop: Arc<AtomicBool>, handles: Vec<JoinHandle<()>>, } impl Pool { - /// Start the dispatcher and `max_concurrent_builds` workers. pub fn spawn(cfg: Arc<Config>, db: Db) -> Pool { let stop = Arc::new(AtomicBool::new(false)); let workers = cfg.max_concurrent_builds.max(1); - // Bounded at the worker count: the dispatcher must not run ahead and - // lease builds that no worker has picked up yet, because a leased build - // whose worker never starts would sit until its lease expires. let (tx, rx) = bounded::<String>(workers); let mut handles = Vec::new(); @@ -53,9 +47,6 @@ impl Pool { Pool { stop, handles } } - /// Ask the threads to stop and wait for them. A build that is mid-step will - /// finish that step, fail its lease, and be requeued by the next process's - /// reaper — which is the designed behaviour, not a bug to wait out. pub fn shutdown(self) { self.stop.store(true, Ordering::SeqCst); for h in self.handles { @@ -65,8 +56,6 @@ impl Pool { } fn dispatcher(cfg: Arc<Config>, db: Db, stop: Arc<AtomicBool>, tx: Sender<String>) { - // The reaper runs first on every loop, including the first, so "recover from - // a crash" and "notice an expired lease" are the same code path. while !stop.load(Ordering::SeqCst) { dispatch_once(&cfg, &db, &tx); let mut slept = 0u64; @@ -77,8 +66,6 @@ fn dispatcher(cfg: Arc<Config>, db: Db, stop: Arc<AtomicBool>, tx: Sender<String } } -/// One dispatcher pass. Returns the ids handed to workers. Public so a test can -/// drive one pass deterministically instead of racing a thread. pub fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> { let reaped = builds::reap_expired(db).unwrap_or(0); if reaped > 0 { @@ -91,7 +78,6 @@ pub fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> ) .ok(); } - // Blocked builds become eligible again when the blocking package arrives. let _ = builds::requeue_blocked(db); let _ = builds::cancel_superseded(db); @@ -103,17 +89,12 @@ pub fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> let ids = builds::claim_batch(db, &owner, room, cfg.lease_secs).unwrap_or_default(); for id in &ids { if tx.send(id.clone()).is_err() { - // No worker to take it: give the lease back rather than let it - // expire with nobody holding it. let _ = builds::requeue_transient(db, id); } } ids } -/// How many builds may be admitted right now (§8.2 backpressure). A build that -/// cannot fit on disk stays queued rather than filling the filesystem halfway -/// through a compile. pub fn admissible(cfg: &Config, db: &Db) -> usize { let in_flight = builds::in_flight(db).unwrap_or(0) as usize; let slots = cfg.max_concurrent_builds.saturating_sub(in_flight); @@ -127,7 +108,6 @@ pub fn admissible(cfg: &Config, db: &Db) -> usize { slots } -/// Megabytes free on the filesystem holding `path`. pub fn free_disk_mb(path: &std::path::Path) -> u64 { use std::ffi::CString; let c = match CString::new(path.as_os_str().to_string_lossy().as_bytes()) { @@ -137,8 +117,6 @@ pub fn free_disk_mb(path: &std::path::Path) -> u64 { let mut stat: libc::statvfs = unsafe { std::mem::zeroed() }; let rc = unsafe { libc::statvfs(c.as_ptr(), &mut stat) }; if rc != 0 { - // If we cannot find out, do not block the queue over a measurement - // problem; the pipeline's own disk guard is the backstop. return u64::MAX; } let bsize = stat.f_frsize as u64; @@ -155,9 +133,6 @@ fn worker(cfg: Arc<Config>, db: Db, rx: crossbeam_channel::Receiver<String>, sto let attempt = builds::get(&db, &id).ok().flatten().map(|b| b.attempt).unwrap_or(1); match pipeline::run(&cfg, &db, &id) { Ok(Outcome::Failed { transient, .. }) => { - // §8.4: transient failures retry with a bounded number of - // attempts; a deterministic failure does not, because it would - // produce the same answer. if transient && attempt < cfg.max_transient_attempts { let _ = builds::requeue_transient(&db, &id); db::audit_system( diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index 308f2a8..9e3c12a 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -13,11 +13,6 @@ use crate::db::SnapshotRow; use crate::error::{Error, Result}; use crate::sandbox::{Sandbox, SandboxBackend}; -/// The approved source identity a build must reproduce. -/// -/// For a new version it comes from the candidate; for a manual rebuild it comes -/// from the accepted release, which is what makes I6 true: a rebuild reuses the -/// approved source identity and never needs a new approval. #[derive(Debug, Clone)] pub struct SourceIdentity { pub aur_commit: String, @@ -30,10 +25,6 @@ pub struct SourceIdentity { } impl SourceIdentity { - /// The identity of a build's source, complete on construction (n-1). The - /// snapshot is an argument because an `aur_commit` that could mean either - /// "not filled in yet" or "genuinely unknown" records empty provenance - /// silently. pub fn from_candidate(c: &CandidateRow, snapshot: &SnapshotRow) -> Self { Self { aur_commit: snapshot.aur_commit.clone(), @@ -61,13 +52,11 @@ impl SourceIdentity { } } -/// One package produced by the build, as recorded by `collect` and `ingest`. #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct CollectedPkg { pub name: String, pub version: String, pub arch: String, - /// Where the artifact lives: staging until `ingest`, the store afterwards. pub path: String, pub digest: String, pub size: u64, @@ -76,7 +65,6 @@ pub struct CollectedPkg { pub makedepends: Vec<String>, pub provides: Vec<String>, pub conflicts: Vec<String>, - /// The full installed set from `.BUILDINFO`, unfiltered (§10.1). pub installed: Vec<(String, String)>, } @@ -98,7 +86,6 @@ impl Collect { } } -/// Everything a step needs. Built once per build run, cheap to clone handles. pub struct Ctx { pub cfg: Config, pub db: Db, @@ -111,8 +98,6 @@ pub struct Ctx { pub log: PathBuf, pub profile: String, pub attempt: i64, - /// Where build code runs. Defaults to the loopback backend (§8, sandbox - /// seam); the pipeline itself never spawns a build subprocess directly. pub backend: Arc<dyn SandboxBackend>, } @@ -126,9 +111,6 @@ impl Ctx { Some(cid) => { let c = crate::review::candidates::candidate_by_id(db, cid)? .ok_or_else(|| Error::not_found("candidate for build"))?; - // A candidate without its snapshot is a broken row, not a - // candidate with less provenance: say so rather than build - // against an empty commit and hash. let snap = db::snapshot_by_id(db, c.snapshot_id)? .ok_or_else(|| Error::not_found("snapshot for candidate"))?; SourceIdentity::from_candidate(&c, &snap) @@ -163,9 +145,6 @@ impl Ctx { }) } - /// Lease a sandbox for this build's profile. The TTL is the lease window: a - /// sandbox that outlives it is assumed dead, which is what the reaper already - /// concludes about an expired build lease. pub fn sandbox(&self) -> Result<Arc<dyn Sandbox>> { let spec = crate::sandbox::SandboxSpec { profile: self.profile.clone(), @@ -176,7 +155,6 @@ impl Ctx { self.backend.acquire(&spec) } - /// Append to the build log; the SSE tail reads this file (§12). pub fn log_line(&self, line: &str) { use std::io::Write; if let Some(parent) = self.log.parent() { @@ -188,7 +166,6 @@ impl Ctx { } } -/// What a full run produced. #[derive(Debug, Clone, PartialEq, Eq)] pub enum Outcome { Succeeded { release_id: i64 }, @@ -197,7 +174,6 @@ pub enum Outcome { Cancelled, } -/// Run a build to completion, resuming at the first incomplete step (I5). pub fn run(cfg: &Config, db: &Db, build_id: &str) -> Result<Outcome> { let ctx = Ctx::new(cfg, db, build_id)?; db::audit_system( @@ -219,7 +195,7 @@ pub fn run_with(ctx: &Ctx) -> Result<Outcome> { } let status = builds::step_status(&ctx.db, &ctx.build.id, step)?; if status.is_some_and(|s| s.is_done()) { - continue; // checkpoint says we already did this + continue; } builds::begin_step(&ctx.db, &ctx.build.id, step, ctx.attempt)?; builds::set_state(&ctx.db, &ctx.build.id, BuildState::Running, None)?; @@ -249,10 +225,6 @@ pub fn run_with(ctx: &Ctx) -> Result<Outcome> { Some(&format!("{step}: {e}")), )?; ctx.log_line(&format!("!! {step} failed: {e}")); - // A failed build must not leave the old version looking healthy. - // Nothing has to do that: the accepted pointer was never moved, - // so the derived query reads it back (§8.4). There is - // deliberately no state to set here. return Ok(Outcome::Failed { step: step.to_string(), error: e.to_string(), transient }); } } @@ -277,8 +249,6 @@ impl Ctx { } } -/// Enqueue the build an approval implies. Deterministic id, so calling this -/// twice is a no-op (§8.2). pub fn enqueue_for_candidate(cfg: &Config, db: &Db, c: &CandidateRow) -> Result<String> { let pb = db::get_pkgbase_by_id(db, c.pkgbase_id)? .ok_or_else(|| Error::not_found("pkgbase"))?; @@ -290,18 +260,11 @@ pub fn enqueue_for_candidate(cfg: &Config, db: &Db, c: &CandidateRow) -> Result< Ok(id) } -/// Manual rebuild of the current accepted version (I6): same source identity, -/// no new approval, same version. pub fn enqueue_manual_rebuild(cfg: &Config, db: &Db, pkgbase: &str) -> Result<String> { let pb = db::get_pkgbase(db, pkgbase)? .ok_or_else(|| Error::not_found(format!("pkgbase {pkgbase}")))?; let rel = db::accepted_release(db, pkgbase)? .ok_or_else(|| Error::invalid(format!("{pkgbase} has no accepted release")))?; - // A manual rebuild is the accepted release asked for again, so its identity - // is derived from what that release actually is, through the same - // canonical-JSON hash every other identity uses (n-5). `requested` is what - // keeps a rebuild a *distinct* build while staying deterministic (§8.2): - // clicking rebuild twice is one build, not two. let identity = format!( "sha256:{}", crate::hash::hex(crate::hash::canonical_json(&serde_json::json!({ @@ -323,10 +286,8 @@ pub fn enqueue_manual_rebuild(cfg: &Config, db: &Db, pkgbase: &str) -> Result<St Ok(id) } -/// What one step produced. pub enum StepResult { Done(Option<String>), Skipped(String), - /// A dependency we publish is not in the index yet (§10.4). Blocked(Vec<String>), } diff --git a/src/pipeline/publish.rs b/src/pipeline/publish.rs index 7340e53..dc9f918 100644 --- a/src/pipeline/publish.rs +++ b/src/pipeline/publish.rs @@ -9,15 +9,6 @@ use crate::error::{Error, Result}; use crate::pipeline::{Collect, Ctx}; use crate::time; -/// One writer to the served repo at a time — *the* serialization guarantee for -/// the index (§8.2, §9, I4). A publish renders a new database in scratch space, -/// commits the DB, then renames over the live one; a second writer interleaving -/// anywhere in that sequence produces an index matching neither DB state. Held by -/// [`publish`] and [`withdraw_package`] for the whole sequence; [`reconcile`] skips -/// it because it runs before the dispatcher exists. -/// -/// A panic while holding it is recovered rather than propagated: atomic publish -/// means a poisoned lock cannot have left a half-written database. static REPO_LOCK: Mutex<()> = Mutex::new(()); fn lock_repo() -> std::sync::MutexGuard<'static, ()> { @@ -27,7 +18,6 @@ fn lock_repo() -> std::sync::MutexGuard<'static, ()> { } } -/// The world a build is admitted against: every pkgbase's accepted version. pub fn index_world(db: &Db) -> Result<Vec<WorldMember>> { let rels = db::all_published_releases(db)?; let mut out = Vec::new(); @@ -40,8 +30,6 @@ pub fn index_world(db: &Db) -> Result<Vec<WorldMember>> { Ok(out) } -/// Package files that belong in the served index right now, plus the extra ones -/// being published (not in the DB yet when the new index is rendered). fn index_artifacts(db: &Db, extra: &[PathBuf]) -> Result<Vec<PathBuf>> { let mut out: Vec<PathBuf> = Vec::new(); for p in db::index_packages(db)? { @@ -55,9 +43,6 @@ fn index_artifacts(db: &Db, extra: &[PathBuf]) -> Result<Vec<PathBuf>> { Ok(out) } -/// Publish the collected artifacts of a build. Returns the new release id. -/// -/// Serialized against every other writer of the index by [`REPO_LOCK`]. pub fn publish(ctx: &Ctx) -> Result<i64> { let _guard = lock_repo(); let collect = Collect::load(&ctx.collect_path)?; @@ -68,13 +53,8 @@ pub fn publish(ctx: &Ctx) -> Result<i64> { let arch_dir = ctx.cfg.repo_arch_dir(); std::fs::create_dir_all(&arch_dir)?; - // Artifacts are copied into the served tree under their real filenames. let mut staged: Vec<(PathBuf, PathBuf)> = Vec::new(); - // Set once the render starts, so the failure path can sweep the scratch - // directory even if the publish died after repo-add returned. let mut scratch_dir: Option<PathBuf> = None; - // Files this publish created that were not there before: if the publish does - // not land they are orphans no index names (§6 m-16). let mut fresh: Vec<PathBuf> = Vec::new(); for p in &collect.packages { let from = PathBuf::from(&p.path); @@ -106,7 +86,6 @@ pub fn publish(ctx: &Ctx) -> Result<i64> { pkgs = dedupe_by_name(pkgs); let rendered = render_db(&ctx.cfg, &arch_dir, "publish", &pkgs, &mut scratch_dir)?; - // Fault injection so I4 can be tested for real (§6 M-9). #[cfg(feature = "test-support")] if ctx.cfg.hooks.publish_fault.as_deref() == Some("before-rename") { return Err(Error::other("injected fault: before-rename")); @@ -141,8 +120,6 @@ pub fn publish(ctx: &Ctx) -> Result<i64> { })(); if outcome.is_err() { - // Nothing in the served tree may look like a publish that did not land - // (m-16); files already there belong to the release still served. for p in &fresh { let _ = std::fs::remove_file(p); } @@ -158,7 +135,6 @@ fn repo_for(db: &Db) -> Result<String> { Ok(id.to_string()) } -/// Insert the release and its package rows, and move the accepted pointer. fn commit_release(ctx: &Ctx, collect: &Collect) -> Result<i64> { let at = time::now(); let pkgbase_id = ctx.pb.id; @@ -167,8 +143,6 @@ fn commit_release(ctx: &Ctx, collect: &Collect) -> Result<i64> { Some(cid) => crate::review::approve::approval_for(&ctx.db, cid)?.map(|(id, _)| id), None => None, }; - // I1: nothing publishes without an approval. A manual rebuild inherits the - // approval of the release it rebuilds. let inherited = match ctx.build.kind.as_str() { "manual_rebuild" => ctx .build @@ -193,8 +167,6 @@ fn commit_release(ctx: &Ctx, collect: &Collect) -> Result<i64> { .flatten() .and_then(|b| b.world_snapshot_id); let repo_id = db::repo_id(&ctx.db)?; - // The compare-and-swap baseline is the release the *approval* was taken - // against, not whatever the pointer says now. let expected_base: Option<i64> = match ctx.build.kind.as_str() { "manual_rebuild" => ctx.build.release_id, _ => ctx @@ -205,15 +177,12 @@ fn commit_release(ctx: &Ctx, collect: &Collect) -> Result<i64> { }; ctx.db.writer.tx(move |tx| { - // Compare-and-swap inside the write transaction (I4). let actual_base = db::accepted_pointer_in(tx, pkgbase_id)?; if actual_base != expected_base { return Err(Error::conflict( "accepted pointer moved while this build was running; refusing to publish", )); } - // The index holds exactly the accepted pointer, so what it held for these - // names goes before the new rows go in. db::remove_index_packages_in(tx, &names)?; let release_id = db::insert_release_in( tx, @@ -249,8 +218,6 @@ fn commit_release(ctx: &Ctx, collect: &Collect) -> Result<i64> { }) } -/// Remove scratch directories a crash left behind: the leading dot means nothing -/// a consumer asks for, and only a render creates one. pub fn sweep_render_dirs(arch_dir: &Path) { let Ok(entries) = std::fs::read_dir(arch_dir) else { return; @@ -262,7 +229,6 @@ pub fn sweep_render_dirs(arch_dir: &Path) { } } -/// A database repo-add has rendered, and the scratch directory it rendered into. struct Rendered { db: PathBuf, dir: PathBuf, @@ -270,8 +236,6 @@ struct Rendered { } impl Rendered { - /// The publish point: rename over the live database, fsync the directory - /// entry, then drop the scratch directory. fn swap_into(self, final_db: &Path) -> Result<()> { std::fs::rename(&self.db, final_db)?; fsync_dir(&self.arch_dir)?; @@ -280,15 +244,6 @@ impl Rendered { } } -/// Render a fresh database with repo-add, ready to be renamed into place. -/// -/// repo-add refuses any database argument that is not a name pacman itself would -/// accept, so the render happens in a scratch directory *under* the served -/// directory, under the exact name a consumer will download. Same filesystem, so -/// the caller's `rename` is still the atomic swap I4 requires. -/// -/// `scratch` is filled in as soon as the directory exists, so the caller can sweep -/// it even if this function is never reached again. fn render_db( cfg: &Config, arch_dir: &Path, @@ -316,8 +271,6 @@ fn render_db( Ok(rendered) } -/// `repo-add -R <db> <pkgs...>`, deliberately *not* `-s`: repo-add would sign into -/// scratch space that gets deleted. The hub signs the live file itself in [`sign`]. fn run_repo_add(cfg: &Config, db_path: &Path, pkgs: &[PathBuf]) -> Result<()> { let mut cmd = Command::new(&cfg.repo_add_bin); cmd.arg("-R"); @@ -344,8 +297,6 @@ fn sign(cfg: &Config, path: &Path) -> Result<()> { sign_to(cfg, path, Path::new(&sig)) } -/// `gpg --detach-sign` over `path`, written to `sig_out` atomically. The key never -/// leaves the hub — a build sandbox signs nothing (§8). pub(crate) fn sign_to(cfg: &Config, path: &Path, sig_out: &Path) -> Result<()> { if cfg.signing_key_id.is_empty() { return Ok(()); @@ -368,8 +319,6 @@ pub(crate) fn sign_to(cfg: &Config, path: &Path, sig_out: &Path) -> Result<()> { Ok(()) } -/// fsync, and *say so* when it fails (m-7). Swallowing the error would make the -/// write-scratch-fsync-rename promise a comment rather than a guarantee. fn fsync_file(p: &Path) -> Result<()> { let f = std::fs::File::open(p) .map_err(|e| Error::other(format!("open {} for fsync: {e}", p.display())))?; @@ -386,9 +335,6 @@ fn fsync_dir(p: &Path) -> Result<()> { Ok(()) } - -/// Keep one entry per package name; the newest file wins. The name comes from -/// `.PKGINFO`, not the filename, because package names contain dashes. fn dedupe_by_name(paths: Vec<PathBuf>) -> Vec<PathBuf> { let mut seen: BTreeSet<String> = BTreeSet::new(); let mut out: Vec<PathBuf> = Vec::new(); @@ -406,10 +352,6 @@ fn dedupe_by_name(paths: Vec<PathBuf>) -> Vec<PathBuf> { out } -/// The package name a built artifact declares, read from its own `.PKGINFO`. -/// -/// The name that goes into the index must come from the same read of the bytes the -/// pipeline signs, so this uses the real parser (§6 M-4). fn package_name(path: &Path) -> Option<String> { let bytes = std::fs::read(path).ok()?; let info = crate::pkginfo::pkginfo_text(&bytes).ok()?; @@ -421,8 +363,6 @@ fn package_name(path: &Path) -> Option<String> { } } -/// Re-materialize the served index from the DB. Run at startup: if a crash left -/// the DB ahead of the file, this closes the gap without inventing anything. pub fn reconcile(cfg: &Config, db: &Db) -> Result<usize> { let pkgs = db::index_packages(db)?; let mut files = Vec::new(); @@ -450,7 +390,6 @@ pub fn reconcile(cfg: &Config, db: &Db) -> Result<usize> { Ok(files.len()) } -/// Remove a package from the served index (§9 withdrawal path). pub fn withdraw_package(cfg: &Config, db: &Db, name: &str) -> Result<()> { let _guard = lock_repo(); let rid = db::repo_id(db)?; diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs index c19ac6b..061593b 100644 --- a/src/pipeline/steps.rs +++ b/src/pipeline/steps.rs @@ -23,9 +23,6 @@ pub fn run_step(ctx: &Ctx, step: &str) -> Result<StepResult> { } } -/// Step 0 — materialize from the local mirror only, never the network, and -/// re-hash what we got. This is the `aur_commit` pin doing its job: there is no -/// path from "AUR moved since the review" to "we built it anyway". fn materialize(ctx: &Ctx) -> Result<StepResult> { let mirror = ctx .pb @@ -62,14 +59,10 @@ fn materialize(ctx: &Ctx) -> Result<StepResult> { Ok(StepResult::Done(Some(computed))) } -/// A display-safe prefix; hashes are 64 hex chars but world digests can be tiny. fn short(s: &str) -> String { s.chars().take(12).collect() } -/// Step 1 — resolve dependencies against the current accepted index and compute -/// the intended world. Unresolvable means "a pkgbase we subscribe to that we have -/// not published yet": block and wait, do not fail (§10.4). fn plan(ctx: &Ctx) -> Result<StepResult> { let recipe = recipe_at(&ctx.srcdir)?; let mut wanted: Vec<String> = Vec::new(); @@ -84,9 +77,8 @@ fn plan(ctx: &Ctx) -> Result<StepResult> { let mut official = 0; for dep in &wanted { if ours.contains(dep) || ctx.pb.name == *dep || recipe.pkgnames.contains(dep) { - continue; // satisfied by our own index, or by this very build + continue; } - // Anything else is only a problem if we are supposed to be publishing it. if db::get_subscription(&ctx.db, dep)?.is_some() || db::get_pkgbase(&ctx.db, dep)?.is_some() { missing.push(dep.clone()); } else { @@ -108,16 +100,6 @@ fn plan(ctx: &Ctx) -> Result<StepResult> { Ok(StepResult::Done(Some(hash))) } -/// Step 2 — provision the sandbox with the pinned lease set. -/// -/// The devtools chroot is gone: the sandbox boots from a base that already carries -/// the official packages, and everything *we* publish arrives as blobs installed -/// with `pacman -U`. The step id stays `chroot` so existing checkpoint rows are -/// not stranded. -/// -/// Nothing is resolved at build time: the lease manifest is the plan, every blob -/// is re-hashed before it is staged, and the sandbox's own `pacman -Q` must confirm -/// the pinned world landed. fn provision(ctx: &Ctx) -> Result<StepResult> { let lease = lease_manifest(ctx)?; if lease.is_empty() { @@ -129,8 +111,6 @@ fn provision(ctx: &Ctx) -> Result<StepResult> { }; for e in &lease { let path = ctx.cfg.store_path(&e.digest); - // The hub hashes what it sends: store corruption is caught here, not - // discovered by a confused package manager inside the sandbox. let (digest, _) = crate::hash::digest_file(&path)?; if digest != e.digest { return Err(Error::fail_closed(format!( @@ -145,15 +125,12 @@ fn provision(ctx: &Ctx) -> Result<StepResult> { argv.extend(lease.iter().map(|e| format!("blob:{}", e.digest))); let out = sbx.run(&Cmd::new(argv), &mut |_| {})?; if !out.success() { - // A refused `-U` is almost always an incomplete closure — "the sandbox lied - // about its world", not "the sandbox broke". return Err(Error::world_mismatch(format!( "{} -U refused the lease set: {}", ctx.cfg.pacman_bin, tail(&out.stderr) ))); } - // Fail-closed world check: the world we approved is the world we build in. let q = sbx.run(&Cmd::new(vec![ctx.cfg.pacman_bin.clone(), "-Q".into()]), &mut |_| {})?; if !q.success() { return Err(Error::fail_closed(format!( @@ -187,8 +164,6 @@ fn provision(ctx: &Ctx) -> Result<StepResult> { Ok(StepResult::Done(Some(crate::hash::canonical_json(&world)?))) } -/// Lease a sandbox for a step, or report that the pool cannot fit one. A full -/// pool blocks the build rather than failing it (§10.4). fn sandbox_or_wait( ctx: &Ctx, ) -> Result<Option<std::sync::Arc<dyn crate::sandbox::Sandbox>>> { @@ -202,7 +177,6 @@ fn sandbox_or_wait( } } -/// One pinned entry of the lease manifest. #[derive(Debug, Clone)] struct LeasePkg { name: String, @@ -210,10 +184,6 @@ struct LeasePkg { digest: String, } -/// The lease manifest: every dependency this build needs that we publish, -/// pinned to the exact version and digest of the artifact we serve. Official -/// packages arrive with the sandbox; anything unresolvable here would have been -/// `plan()`'s problem. fn lease_manifest(ctx: &Ctx) -> Result<Vec<LeasePkg>> { let recipe = recipe_at(&ctx.srcdir)?; let mut wanted: Vec<String> = Vec::new(); @@ -225,7 +195,7 @@ fn lease_manifest(ctx: &Ctx) -> Result<Vec<LeasePkg>> { let mut out = Vec::new(); for dep in wanted { if dep == ctx.pb.name || recipe.pkgnames.contains(&dep) { - continue; // this build's own output is not its own dependency + continue; } if let Some((version, digest)) = db::index_artifact(&ctx.db, &dep)? { out.push(LeasePkg { name: dep, version, digest }); @@ -234,18 +204,12 @@ fn lease_manifest(ctx: &Ctx) -> Result<Vec<LeasePkg>> { Ok(out) } -/// Step 3 — make sure every source we reviewed is on disk and hashes to what the -/// candidate recorded. For a `SKIP` source this is the only verification that -/// exists (§8.1). fn sources(ctx: &Ctx) -> Result<StepResult> { let digests: Vec<SourceDigest> = serde_json::from_str(&ctx.src.source_digests_json).unwrap_or_default(); let mut verified = 0; for d in &digests { match d.kind.as_str() { - // Already materialized from the mirror at the pinned commit. "local" => verified += 1, - // VCS kinds (git/svn/hg/bzr): honouring upstream_pins at build time - // is deferred to P1 (§20); the pkgver assertion is the interim guard. "vcs" | "git" | "svn" | "hg" | "bzr" => verified += 1, _ => { let (digest, _size) = match cached_path(&ctx.db, &d.url, &d.digest) { @@ -268,8 +232,6 @@ fn sources(ctx: &Ctx) -> Result<StepResult> { )))) } -/// Step 4 — the belt-and-braces assertion that what we build is what was approved. -/// If upstream moved between approval and build, fail with both versions (§8.1). fn pkgver(ctx: &Ctx) -> Result<StepResult> { let recipe = recipe_at(&ctx.srcdir)?; let has_vcs = recipe.source_entries.iter().any(|s| s.is_vcs()); @@ -308,18 +270,12 @@ fn pkgver(ctx: &Ctx) -> Result<StepResult> { Ok(StepResult::Done(Some(text))) } -/// Step 5 — `makepkg -c -f` in the provisioned sandbox, with the log going to -/// the file the SSE tail reads. No `-s`: the lease set is already installed, and -/// resolving dependencies at build time is what the pinning model forbids. No -/// `-si`: the sandbox never holds the signing key. fn build(ctx: &Ctx) -> Result<StepResult> { let argv = vec![ctx.cfg.makepkg_bin.clone(), "-c".into(), "-f".into()]; let sbx = match sandbox_or_wait(ctx)? { Some(s) => s, None => return Ok(StepResult::Blocked(vec!["sandbox-pool".into()])), }; - // The sandbox streams the child's output here as it arrives; the SSE tail - // reads the same file. if let Some(parent) = ctx.log.parent() { let _ = std::fs::create_dir_all(parent); } @@ -331,7 +287,7 @@ fn build(ctx: &Ctx) -> Result<StepResult> { } }; let out = sbx.run(&Cmd::new(argv).in_dir(&ctx.srcdir), &mut on_log)?; - drop(on_log); // closes the log file before the outcome is recorded + drop(on_log); if !out.success() { return Err(Error::Subprocess { cmd: ctx.cfg.makepkg_bin.clone(), @@ -350,8 +306,6 @@ fn tail(b: &[u8]) -> String { lines[lines.len().saturating_sub(6)..].join(" | ") } -/// Step 6 — parse `.PKGINFO`/`.BUILDINFO` out of the produced artifacts (§10.1: -/// plain text in a tar, no libalpm needed). fn collect(ctx: &Ctx) -> Result<StepResult> { let mut pkgs = Vec::new(); let mut entries: Vec<PathBuf> = std::fs::read_dir(&ctx.srcdir)? @@ -360,11 +314,6 @@ fn collect(ctx: &Ctx) -> Result<StepResult> { .filter(|p| p.to_string_lossy().ends_with(".pkg.tar.zst")) .collect(); entries.sort(); - // I9: the build is untrusted, and the control plane must not *depend* on the - // sandbox for its own safety. Everything below takes a path a PKGBUILD could - // have arranged to exist in the srcdir, and the next step copies whatever it - // points at into the store, from where we serve and sign it. So: no symlinks, - // and the resolved target must live inside this build's staging directory. let staging_root = ctx.staging.canonicalize()?;; for path in entries { if std::fs::symlink_metadata(&path).map(|m| m.file_type().is_symlink()).unwrap_or(true) { @@ -383,13 +332,9 @@ fn collect(ctx: &Ctx) -> Result<StepResult> { let path = resolved; let bytes = std::fs::read(&path)?; let (digest, size) = crate::hash::digest_file(&path)?; - // Read what the package says about itself out of the archive, rather - // than trusting what the build claimed on stdout (§10.1). let pkginfo = crate::pkginfo::pkginfo_text(&bytes) .map_err(|e| Error::invalid(format!("{}: {e}", path.display())))?; let meta = crate::pkginfo::parse_pkginfo(&pkginfo); - // `.BUILDINFO` is what the world snapshot is built from. Absent is not - // fatal; present-but-unparseable would be a lie we should not swallow. let buildinfo = crate::pkginfo::buildinfo_text(&bytes).unwrap_or_default(); let sig = path.with_extension("pkg.tar.zst.sig"); pkgs.push(CollectedPkg { @@ -419,8 +364,6 @@ fn collect(ctx: &Ctx) -> Result<StepResult> { Ok(StepResult::Done(Some(crate::hash::hex_str(&serde_json::to_string(&pkgs)?)))) } -/// Step 7 — dependencies satisfiable, no downgrade. Signature checking is not -/// here: the sandbox never sees the key, so the signature is made at ingest. fn verify(ctx: &Ctx) -> Result<StepResult> { let collect = Collect::load(&ctx.collect_path)?; let ours = db::our_package_names(&ctx.db)?; @@ -429,7 +372,6 @@ fn verify(ctx: &Ctx) -> Result<StepResult> { &db::index_version(&ctx.db, &p.name)?.unwrap_or_else(|| "0".into()), &p.version, ) { - // Downgrades are allowed but flagged (§16); the review already shows it. ctx.log_line(&format!(" note: {} is a downgrade from what we serve", p.name)); } let mut provided: std::collections::BTreeSet<String> = ours.clone(); @@ -449,8 +391,6 @@ fn verify(ctx: &Ctx) -> Result<StepResult> { )?)))) } -/// Step 8 — move artifacts into the content-addressed store and record rows. -/// Staging stays disposable; a GC pass sweeps abandoned directories (§8.2). fn ingest(ctx: &Ctx) -> Result<StepResult> { let mut collect = Collect::load(&ctx.collect_path)?; for p in &mut collect.packages { @@ -463,8 +403,6 @@ fn ingest(ctx: &Ctx) -> Result<StepResult> { std::fs::copy(from, &dest)?; } p.path = dest.display().to_string(); - // Hub-side signing: over the exact bytes that just entered the store. A - // gpg failure fails the build closed. if !ctx.cfg.signing_key_id.is_empty() { let sigdest = ctx.cfg.store_path(&format!("{}-sig", p.digest)); if !sigdest.exists() { @@ -498,9 +436,6 @@ fn ingest(ctx: &Ctx) -> Result<StepResult> { Ok(()) })?; - // §10.1: the world snapshot is the build's installed set INTERSECTED with our - // own packages, filtered at ingest time. Left unfiltered, every package would - // be permanently stale because Arch never stops moving. let ours = db::our_package_names(&ctx.db)?; let mut members: Vec<WorldMember> = Vec::new(); for p in &collect.packages { @@ -519,7 +454,6 @@ fn ingest(ctx: &Ctx) -> Result<StepResult> { ))))) } -/// Step 9 — the only externally visible step, serialized per repo (§9). fn publish(ctx: &Ctx) -> Result<StepResult> { let release_id = crate::pipeline::publish::publish(ctx)?; Ok(StepResult::Done(Some(format!("release:{release_id}")))) @@ -529,7 +463,6 @@ fn publish(ctx: &Ctx) -> Result<StepResult> { use std::path::PathBuf; -/// Read the recipe from a materialized tree, preferring `.SRCINFO`. pub(crate) fn recipe_at(dir: &Path) -> Result<Recipe> { let mut files = std::collections::BTreeMap::new(); for entry in walkdir::WalkDir::new(dir).max_depth(2).into_iter().filter_map(|e| e.ok()) { |
