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/steps.rs | 85 ++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 55 deletions(-) (limited to 'src/pipeline/steps.rs') diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs index 775485d..9703d54 100644 --- a/src/pipeline/steps.rs +++ b/src/pipeline/steps.rs @@ -1,6 +1,9 @@ use std::path::Path; -use crate::db::{self, builds, model::*}; +use crate::db::{ + self, builds, + model::{Recipe, SourceDigest, WorldMember}, +}; use crate::error::{Error, Guard, Result, WorldGap}; use crate::git; use crate::pipeline::{Collect, CollectedPkg, Ctx, StepResult}; @@ -29,8 +32,7 @@ fn materialize(ctx: &Ctx) -> Result { .mirror_path .as_ref() .map(Path::new) - .map(|p| p.to_path_buf()) - .unwrap_or_else(|| ctx.cfg.mirror_path(&ctx.pb.name)); + .map_or_else(|| ctx.cfg.mirror_path(&ctx.pb.name), std::path::Path::to_path_buf); if !mirror.exists() { return Err(Error::fail_closed(format!( "mirror {} missing; refusing to fetch a recipe from the network at build time", @@ -105,10 +107,7 @@ fn provision(ctx: &Ctx) -> Result { if lease.is_empty() { return Ok(StepResult::Skipped("no of-our-packages dependencies to install".into())); } - let sbx = match sandbox_or_wait(ctx)? { - Some(s) => s, - None => return Ok(StepResult::Blocked(vec!["sandbox-pool".into()])), - }; + let Some(sbx) = sandbox_or_wait(ctx)? else { return Ok(StepResult::Blocked(vec!["sandbox-pool".into()])) }; for e in &lease { let path = ctx.cfg.store_path(&e.digest); let (digest, _) = crate::hash::digest_file(&path)?; @@ -134,11 +133,7 @@ fn provision(ctx: &Ctx) -> Result { } let q = sbx.run(&Cmd::new(vec![ctx.cfg.pacman_bin.clone(), "-Q".into()]), &mut |_| {})?; if !q.success() { - return Err(Error::fail_closed(format!( - "{} -Q failed: {}", - ctx.cfg.pacman_bin, - tail(&q.stderr) - ))); + return Err(Error::fail_closed(format!("{} -Q failed: {}", ctx.cfg.pacman_bin, tail(&q.stderr)))); } let installed: std::collections::BTreeSet<(String, String)> = String::from_utf8_lossy(&q.stdout) .lines() @@ -150,9 +145,7 @@ fn provision(ctx: &Ctx) -> Result { .collect(); for e in &lease { if !installed.contains(&(e.name.clone(), e.version.clone())) { - return Err(Error::world_mismatch(WorldGap::MissingPin { - package: format!("{}-{}", e.name, e.version), - })); + return Err(Error::world_mismatch(WorldGap::MissingPin { package: format!("{}-{}", e.name, e.version) })); } } ctx.log_line(&format!( @@ -164,9 +157,7 @@ fn provision(ctx: &Ctx) -> Result { Ok(StepResult::Done(Some(crate::hash::canonical_json(&world)?))) } -fn sandbox_or_wait( - ctx: &Ctx, -) -> Result>> { +fn sandbox_or_wait(ctx: &Ctx) -> Result>> { match ctx.sandbox() { Ok(s) => Ok(Some(s)), Err(e) if e.is_pool_exhausted() => { @@ -218,14 +209,12 @@ fn sources(ctx: &Ctx) -> Result { } } ctx.log_line(&format!(" {}/{} source digests verified", verified, digests.len())); - Ok(StepResult::Done(Some(crate::hash::hex_str( - &ctx.src.source_digests_json, - )))) + Ok(StepResult::Done(Some(crate::hash::hex_str(&ctx.src.source_digests_json)))) } fn pkgver(ctx: &Ctx) -> Result { let recipe = recipe_at(&ctx.srcdir)?; - let has_vcs = recipe.source_entries.iter().any(|s| s.is_vcs()); + let has_vcs = recipe.source_entries.iter().any(super::super::db::model::SourceEntry::is_vcs); if !has_vcs { let want = (ctx.src.pkgver.clone(), ctx.src.pkgrel.clone()); let got = (recipe.pkgver.clone(), recipe.pkgrel.clone()); @@ -263,10 +252,7 @@ fn pkgver(ctx: &Ctx) -> Result { fn build(ctx: &Ctx) -> Result { 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()])), - }; + let Some(sbx) = sandbox_or_wait(ctx)? else { return Ok(StepResult::Blocked(vec!["sandbox-pool".into()])) }; if let Some(parent) = ctx.log.parent() { let _ = std::fs::create_dir_all(parent); } @@ -280,15 +266,9 @@ fn build(ctx: &Ctx) -> Result { let out = sbx.run(&Cmd::new(argv).in_dir(&ctx.srcdir), &mut on_log)?; drop(on_log); if !out.success() { - return Err(Error::Subprocess { - cmd: ctx.cfg.makepkg_bin.clone(), - detail: tail(&out.stderr), - }); + return Err(Error::Subprocess { cmd: ctx.cfg.makepkg_bin.clone(), detail: tail(&out.stderr) }); } - Ok(StepResult::Done(Some(crate::hash::hex_str(&format!( - "build:{}", - ctx.build.id - ))))) + Ok(StepResult::Done(Some(crate::hash::hex_str(&format!("build:{}", ctx.build.id))))) } fn tail(b: &[u8]) -> String { @@ -300,14 +280,14 @@ fn tail(b: &[u8]) -> String { fn collect(ctx: &Ctx) -> Result { let mut pkgs = Vec::new(); let mut entries: Vec = std::fs::read_dir(&ctx.srcdir)? - .filter_map(|e| e.ok()) + .filter_map(std::result::Result::ok) .map(|e| e.path()) .filter(|p| p.to_string_lossy().ends_with(".pkg.tar.zst")) .collect(); entries.sort(); 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) { + if std::fs::symlink_metadata(&path).map_or(true, |m| m.file_type().is_symlink()) { return Err(Error::fail_closed(format!( "{} is a symlink; a build may not smuggle bytes in from outside its own staging dir", path.display() @@ -316,15 +296,16 @@ fn collect(ctx: &Ctx) -> Result { let resolved = path.canonicalize()?; if !resolved.starts_with(&staging_root) { return Err(Error::fail_closed(format!( - "{} resolves outside this build's staging dir ({staging_root:?}); refusing to ingest it", - path.display() + "{} resolves outside this build's staging dir ({}); refusing to ingest it", + path.display(), + staging_root.display() ))); } let path = resolved; let bytes = std::fs::read(&path)?; let (digest, size) = crate::hash::digest_file(&path)?; - let pkginfo = crate::pkginfo::pkginfo_text(&bytes) - .map_err(|e| Error::invalid(format!("{}: {e}", path.display())))?; + let pkginfo = + crate::pkginfo::pkginfo_text(&bytes).map_err(|e| Error::invalid(format!("{}: {e}", path.display())))?; let meta = crate::pkginfo::parse_pkginfo(&pkginfo); let buildinfo = crate::pkginfo::buildinfo_text(&bytes).unwrap_or_default(); let sig = path.with_extension("pkg.tar.zst.sig"); @@ -340,10 +321,7 @@ fn collect(ctx: &Ctx) -> Result { makedepends: meta.makedepends.clone(), provides: meta.provides.clone(), conflicts: meta.conflicts.clone(), - installed: crate::pkginfo::parse_installed(&buildinfo) - .into_iter() - .map(|i| (i.name, i.version)) - .collect(), + installed: crate::pkginfo::parse_installed(&buildinfo).into_iter().map(|i| (i.name, i.version)).collect(), }); } if pkgs.is_empty() { @@ -351,7 +329,10 @@ fn collect(ctx: &Ctx) -> Result { } let collect = Collect { packages: pkgs.clone() }; collect.save(&ctx.collect_path)?; - ctx.log_line(&format!(" collected {}", pkgs.iter().map(|p| format!("{}-{}", p.name, p.version)).collect::>().join(", "))); + ctx.log_line(&format!( + " collected {}", + pkgs.iter().map(|p| format!("{}-{}", p.name, p.version)).collect::>().join(", ") + )); Ok(StepResult::Done(Some(crate::hash::hex_str(&serde_json::to_string(&pkgs)?)))) } @@ -359,10 +340,8 @@ fn verify(ctx: &Ctx) -> Result { let collect = Collect::load(&ctx.collect_path)?; let ours = db::our_package_names(&ctx.db)?; for p in &collect.packages { - if crate::pkgver::is_downgrade( - &db::index_version(&ctx.db, &p.name)?.unwrap_or_else(|| "0".into()), - &p.version, - ) { + if crate::pkgver::is_downgrade(&db::index_version(&ctx.db, &p.name)?.unwrap_or_else(|| "0".into()), &p.version) + { ctx.log_line(&format!(" note: {} is a downgrade from what we serve", p.name)); } let mut provided: std::collections::BTreeSet = ours.clone(); @@ -439,10 +418,7 @@ fn ingest(ctx: &Ctx) -> Result { let world_id = db::put_world_snapshot(&ctx.db.writer, &members)?; builds::set_world(&ctx.db, &ctx.build.id, world_id)?; ctx.log_line(&format!(" ingested {} artifact(s), world has {} of our packages", packages.len(), members.len())); - Ok(StepResult::Done(Some(crate::hash::hex_str(&format!( - "ingest:{}", - packages.len() - ))))) + Ok(StepResult::Done(Some(crate::hash::hex_str(&format!("ingest:{}", packages.len()))))) } fn publish(ctx: &Ctx) -> Result { @@ -456,7 +432,7 @@ use std::path::PathBuf; fn recipe_at(dir: &Path) -> Result { let mut files = std::collections::BTreeMap::new(); - for entry in walkdir::WalkDir::new(dir).max_depth(2).into_iter().filter_map(|e| e.ok()) { + for entry in walkdir::WalkDir::new(dir).max_depth(2).into_iter().filter_map(std::result::Result::ok) { let p = entry.path(); if !p.is_file() { continue; @@ -468,4 +444,3 @@ fn recipe_at(dir: &Path) -> Result { } crate::recipe::recipe_from_tree(&files) } - -- cgit v1.2.3