diff options
Diffstat (limited to 'src/pipeline/steps.rs')
| -rw-r--r-- | src/pipeline/steps.rs | 85 |
1 files changed, 30 insertions, 55 deletions
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<StepResult> { .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<StepResult> { 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<StepResult> { } 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<StepResult> { .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<StepResult> { Ok(StepResult::Done(Some(crate::hash::canonical_json(&world)?))) } -fn sandbox_or_wait( - ctx: &Ctx, -) -> Result<Option<std::sync::Arc<dyn crate::sandbox::Sandbox>>> { +fn sandbox_or_wait(ctx: &Ctx) -> Result<Option<std::sync::Arc<dyn crate::sandbox::Sandbox>>> { match ctx.sandbox() { Ok(s) => Ok(Some(s)), Err(e) if e.is_pool_exhausted() => { @@ -218,14 +209,12 @@ fn sources(ctx: &Ctx) -> Result<StepResult> { } } 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<StepResult> { 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<StepResult> { 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()])), - }; + 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<StepResult> { 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<StepResult> { let mut pkgs = Vec::new(); let mut entries: Vec<PathBuf> = 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<StepResult> { 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<StepResult> { 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<StepResult> { } 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::<Vec<_>>().join(", "))); + ctx.log_line(&format!( + " collected {}", + pkgs.iter().map(|p| format!("{}-{}", p.name, p.version)).collect::<Vec<_>>().join(", ") + )); Ok(StepResult::Done(Some(crate::hash::hex_str(&serde_json::to_string(&pkgs)?)))) } @@ -359,10 +340,8 @@ fn verify(ctx: &Ctx) -> Result<StepResult> { 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<String> = ours.clone(); @@ -439,10 +418,7 @@ fn ingest(ctx: &Ctx) -> Result<StepResult> { 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<StepResult> { @@ -456,7 +432,7 @@ use std::path::PathBuf; 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()) { + 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<Recipe> { } crate::recipe::recipe_from_tree(&files) } - |
