From 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 Mon Sep 17 00:00:00 2001 From: aur-build Date: Sun, 22 Nov 2026 10:36:24 +0000 Subject: rustfmt,lints: pin the formatting, adopt the idiom lints, pay them off rustfmt.toml fixes the shape the tree is written in (120 columns, small items kept on one line) and one canonical pass makes it the truth. [lints.clippy] names the idiom lints worth enforcing and leaves out the two that would add doc-comment boilerplate rather than remove it. The tree pays them off here: write!/writeln! instead of push_str(&format!()), let-else instead of match-on-Option, borrows where a thread entry point only reads what it owns, no `&self` on a Copy state and no `self` nobody reads. ops::to_prometheus gains one gauge helper: a metric's HELP, TYPE and value are now emitted by the same call instead of three. --- src/pipeline/mod.rs | 71 +++++++++++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 43 deletions(-) (limited to 'src/pipeline/mod.rs') diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index 3e63a69..5bc7cdb 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -1,5 +1,5 @@ -pub mod publish; pub mod dispatch; +pub mod publish; mod steps; use std::path::PathBuf; @@ -7,9 +7,9 @@ use std::sync::Arc; use std::time::Duration; use crate::config::Config; -use crate::db::{self, builds, Db, Pkgbase}; -use crate::db::model::*; +use crate::db::model::{BuildState, CandidateRow, ReleaseRow, StepState}; use crate::db::SnapshotRow; +use crate::db::{self, builds, Db, Pkgbase}; use crate::error::{Error, Missing, Result}; use crate::sandbox::{Sandbox, SandboxBackend}; @@ -103,26 +103,17 @@ pub struct Ctx { impl Ctx { pub fn new(cfg: &Config, db: &Db, build_id: &str) -> Result { - let build = builds::get(db, build_id)? - .ok_or_else(|| Error::not_found(Missing::Build(build_id.to_string())))?; - let pb = db::get_pkgbase_by_id(db, build.pkgbase_id)? - .ok_or_else(|| Error::not_found("pkgbase for build"))?; - let src = match build.candidate_id { - Some(cid) => { - let c = crate::review::reads::candidate(db, cid)? - .ok_or_else(|| Error::not_found("candidate for build"))?; - let snap = db::snapshot_by_id(db, c.snapshot_id)? - .ok_or_else(|| Error::not_found("snapshot for candidate"))?; - SourceIdentity::from_candidate(&c, &snap) - } - None => { - let rid = build - .release_id - .ok_or_else(|| Error::invalid("build has neither candidate nor release"))?; - let r = db::release_by_id(db, rid)? - .ok_or_else(|| Error::not_found("release for rebuild"))?; - SourceIdentity::from_release(&r) - } + let build = builds::get(db, build_id)?.ok_or_else(|| Error::not_found(Missing::Build(build_id.to_string())))?; + let pb = db::get_pkgbase_by_id(db, build.pkgbase_id)?.ok_or_else(|| Error::not_found("pkgbase for build"))?; + let src = if let Some(cid) = build.candidate_id { + let c = crate::review::reads::candidate(db, cid)?.ok_or_else(|| Error::not_found("candidate for build"))?; + let snap = + db::snapshot_by_id(db, c.snapshot_id)?.ok_or_else(|| Error::not_found("snapshot for candidate"))?; + SourceIdentity::from_candidate(&c, &snap) + } else { + let rid = build.release_id.ok_or_else(|| Error::invalid("build has neither candidate nor release"))?; + let r = db::release_by_id(db, rid)?.ok_or_else(|| Error::not_found("release for rebuild"))?; + SourceIdentity::from_release(&r) }; let attempt = build.attempt; let profile = build.build_profile.clone(); @@ -231,20 +222,13 @@ fn run_with_impl(ctx: &Ctx) -> Result { Err(e) => { let transient = e.is_transient(); builds::finish_step(&ctx.db, &ctx.build.id, step, StepState::Failed, None, Some(&e.to_string()))?; - builds::set_state( - &ctx.db, - &ctx.build.id, - BuildState::Failed, - Some(&format!("{step}: {e}")), - )?; + builds::set_state(&ctx.db, &ctx.build.id, BuildState::Failed, Some(&format!("{step}: {e}")))?; ctx.log_line(&format!("!! {step} failed: {e}")); return Ok(Outcome::Failed { step: step.to_string(), error: e.to_string(), transient }); } } } - let release_id = ctx - .release_id() - .ok_or_else(|| Error::other("publish produced no release"))?; + let release_id = ctx.release_id().ok_or_else(|| Error::other("publish produced no release"))?; builds::set_state(&ctx.db, &ctx.build.id, BuildState::Succeeded, None)?; db::audit_system( &ctx.db.writer, @@ -263,8 +247,7 @@ impl Ctx { } pub fn enqueue_for_candidate(cfg: &Config, db: &Db, c: &CandidateRow) -> Result { - let pb = db::get_pkgbase_by_id(db, c.pkgbase_id)? - .ok_or_else(|| Error::not_found("pkgbase"))?; + let pb = db::get_pkgbase_by_id(db, c.pkgbase_id)?.ok_or_else(|| Error::not_found("pkgbase"))?; let world = publish::index_world(db)?; let world_hash = crate::hash::canonical_json(&world)?; let id = builds::build_id(&pb.name, &c.identity_hash, &world_hash, &cfg.build_profile); @@ -274,19 +257,21 @@ pub fn enqueue_for_candidate(cfg: &Config, db: &Db, c: &CandidateRow) -> Result< } pub fn enqueue_manual_rebuild(cfg: &Config, db: &Db, pkgbase: &str) -> Result { - let pb = db::get_pkgbase(db, pkgbase)? - .ok_or_else(|| Error::not_found(Missing::Pkgbase(pkgbase.to_string())))?; + let pb = db::get_pkgbase(db, pkgbase)?.ok_or_else(|| Error::not_found(Missing::Pkgbase(pkgbase.to_string())))?; let rel = db::accepted_release(db, pkgbase)? .ok_or_else(|| Error::invalid(format!("{pkgbase} has no accepted release")))?; let identity = format!( "sha256:{}", - crate::hash::hex(crate::hash::canonical_json(&serde_json::json!({ - "aur_commit": rel.aur_commit, - "recipe_hash": rel.recipe_hash, - "upstream_pins": rel.pins(), - "source_digests": rel.digests(), - "requested": "manual_rebuild", - }))?.as_bytes()) + crate::hash::hex( + crate::hash::canonical_json(&serde_json::json!({ + "aur_commit": rel.aur_commit, + "recipe_hash": rel.recipe_hash, + "upstream_pins": rel.pins(), + "source_digests": rel.digests(), + "requested": "manual_rebuild", + }))? + .as_bytes() + ) ); let world = publish::index_world(db)?; let world_hash = crate::hash::canonical_json(&world)?; -- cgit v1.2.3