summaryrefslogtreecommitdiffstats
path: root/src/pipeline
diff options
context:
space:
mode:
Diffstat (limited to 'src/pipeline')
-rw-r--r--src/pipeline/mod.rs8
-rw-r--r--src/pipeline/publish.rs92
-rw-r--r--src/pipeline/steps.rs16
3 files changed, 39 insertions, 77 deletions
diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs
index 8f4012e..279ec0f 100644
--- a/src/pipeline/mod.rs
+++ b/src/pipeline/mod.rs
@@ -304,13 +304,7 @@ pub fn enqueue_manual_rebuild(cfg: &Config, db: &Db, pkgbase: &str) -> Result<St
builds::enqueue(db, &id, pb.id, None, "manual_rebuild", Some(world_id), &cfg.build_profile, 1)?;
let id_for_tx = id.clone();
let rid = rel.id;
- db.writer.tx(move |tx| {
- tx.execute(
- "UPDATE build SET release_id=?1 WHERE id=?2",
- rusqlite::params![rid, id_for_tx],
- )?;
- Ok(())
- })?;
+ db.writer.tx(move |tx| builds::set_release_in(tx, &id_for_tx, rid))?;
Ok(id)
}
diff --git a/src/pipeline/publish.rs b/src/pipeline/publish.rs
index d54314e..ab0cb87 100644
--- a/src/pipeline/publish.rs
+++ b/src/pipeline/publish.rs
@@ -11,10 +11,8 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::Mutex;
-use rusqlite::OptionalExtension;
-
use crate::config::Config;
-use crate::db::{self, builds, Db, WorldMember};
+use crate::db::{self, builds, candidate_state, candidates, Db, WorldMember};
use crate::error::{Error, Result};
use crate::pipeline::{Collect, Ctx};
use crate::time;
@@ -43,12 +41,7 @@ fn index_artifacts(db: &Db, extra: &[PathBuf]) -> Result<Vec<PathBuf>> {
let mut out: Vec<PathBuf> = Vec::new();
for p in db::index_packages(db)? {
if let Some(aid) = p.artifact_id {
- let path: Option<String> = db.read(|c| {
- use rusqlite::OptionalExtension;
- Ok(c.query_row("SELECT path FROM artifact WHERE id=?1", rusqlite::params![aid], |r| r.get(0))
- .optional()?)
- })?;
- if let Some(p) = path.map(PathBuf::from).filter(|p| p.exists()) {
+ if let Some(p) = db::artifact_path(db, aid)?.map(PathBuf::from).filter(|p| p.exists()) {
out.push(p);
}
}
@@ -205,11 +198,7 @@ fn commit_release(ctx: &Ctx, collect: &Collect) -> Result<i64> {
ctx.db.writer.tx(move |tx| {
// Compare-and-swap on the accepted pointer, inside the write
// transaction: two publishes cannot both land (I4).
- let actual_base: Option<i64> = tx.query_row(
- "SELECT current_accepted_release_id FROM pkgbase WHERE id=?1",
- rusqlite::params![pkgbase_id],
- |r| r.get(0),
- )?;
+ 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",
@@ -217,52 +206,36 @@ fn commit_release(ctx: &Ctx, collect: &Collect) -> Result<i64> {
}
// Retire whatever the index held for these names *before* inserting the
// new rows: the index holds exactly the accepted pointer, nothing else.
- if !names.is_empty() {
- let ph = names.iter().map(|_| "?").collect::<Vec<_>>().join(",");
- let sql = format!(
- "UPDATE package SET state='removed' WHERE state='in_index' AND name IN ({ph})"
- );
- let mut stmt = tx.prepare(&sql)?;
- stmt.execute(rusqlite::params_from_iter(names.iter().map(|n| n as &dyn rusqlite::ToSql)))?;
- }
- tx.execute(
- "INSERT INTO release (pkgbase_id, candidate_id, approval_id, aur_commit, recipe_hash,
- upstream_pins_json, source_digests_json, epoch, pkgver, pkgrel,
- world_snapshot_id, state, build_id, published_at, created_at)
- VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,'published',?12,?13,?13)",
- rusqlite::params![
- pkgbase_id, candidate_id, approval_id, src.aur_commit, src.recipe_hash,
- src.upstream_pins_json, src.source_digests_json, src.epoch, src.pkgver, src.pkgrel,
- world_id, build_id, at
- ],
+ db::remove_index_packages_in(tx, &names)?;
+ let release_id = db::insert_release_in(
+ tx,
+ &db::NewRelease {
+ pkgbase_id,
+ candidate_id,
+ approval_id: Some(approval_id),
+ aur_commit: &src.aur_commit,
+ recipe_hash: &src.recipe_hash,
+ upstream_pins_json: &src.upstream_pins_json,
+ source_digests_json: &src.source_digests_json,
+ epoch: &src.epoch,
+ pkgver: &src.pkgver,
+ pkgrel: &src.pkgrel,
+ world_snapshot_id: world_id,
+ build_id: &build_id,
+ },
+ &at,
)?;
- let release_id = tx.last_insert_rowid();
for p in &packages {
- let artifact_id: Option<i64> = tx
- .query_row(
- "SELECT id FROM artifact WHERE digest=?1",
- rusqlite::params![p.digest],
- |r| r.get(0),
- )
- .optional()?;
- tx.execute(
- "INSERT INTO package (repo_id, release_id, name, arch, version, artifact_id, state)
- VALUES (?1,?2,?3,?4,?5,?6,'in_index')",
- rusqlite::params![repo_id, release_id, p.name, p.arch, p.version, artifact_id],
- )?;
+ db::insert_package_in(tx, repo_id, release_id, &p.name, &p.arch, &p.version, &p.digest)?;
}
- let moved = tx.execute(
- "UPDATE pkgbase SET current_accepted_release_id=?1 WHERE id=?2 AND current_accepted_release_id IS ?3",
- rusqlite::params![release_id, pkgbase_id, expected_base],
- )?;
- if moved != 1 {
+ if !db::cas_accepted_release_in(tx, pkgbase_id, release_id, expected_base)? {
return Err(Error::conflict(
"accepted pointer moved while this build was running; refusing to publish",
));
}
- tx.execute("UPDATE build SET release_id=?1 WHERE id=?2", rusqlite::params![release_id, build_id])?;
+ builds::set_release_in(tx, &build_id, release_id)?;
if let Some(cid) = candidate_id {
- tx.execute("UPDATE candidate SET state='approved' WHERE id=?1", rusqlite::params![cid])?;
+ candidates::resolve_in(tx, cid, candidate_state::APPROVED, &at)?;
}
Ok(release_id)
})
@@ -366,12 +339,7 @@ pub fn reconcile(cfg: &Config, db: &Db) -> Result<usize> {
let mut files = Vec::new();
for p in &pkgs {
if let Some(aid) = p.artifact_id {
- let path: Option<String> = db.read(|c| {
- use rusqlite::OptionalExtension;
- Ok(c.query_row("SELECT path FROM artifact WHERE id=?1", rusqlite::params![aid], |r| r.get(0))
- .optional()?)
- })?;
- if let Some(path) = path.map(PathBuf::from).filter(|p| p.exists()) {
+ if let Some(path) = db::artifact_path(db, aid)?.map(PathBuf::from).filter(|p| p.exists()) {
let arch_dir = cfg.repo_arch_dir();
let _ = std::fs::create_dir_all(&arch_dir);
let dest = arch_dir.join(format!("{}-{}-{}.pkg.tar.zst", p.name, p.version, p.arch));
@@ -397,13 +365,7 @@ pub fn withdraw_package(cfg: &Config, db: &Db, name: &str) -> Result<()> {
let _guard = REPO_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let rid = db::repo_id(db)?;
let n = name.to_string();
- db.writer.tx(move |tx| {
- tx.execute(
- "UPDATE package SET state='removed' WHERE repo_id=?1 AND name=?2",
- rusqlite::params![rid, n],
- )?;
- Ok(())
- })?;
+ db.writer.tx(move |tx| db::remove_package_by_name_in(tx, rid, &n))?;
let arch_dir = cfg.repo_arch_dir();
let tmp = arch_dir.join(format!("{}.tar.gz.tmp", cfg.repo_db_name()));
let files = index_artifacts(db, &[])?;
diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs
index 6bdf12c..033093b 100644
--- a/src/pipeline/steps.rs
+++ b/src/pipeline/steps.rs
@@ -390,11 +390,17 @@ fn ingest(ctx: &Ctx) -> Result<StepResult> {
let log_path = ctx.log.display().to_string();
ctx.db.writer.tx(move |tx| {
for p in &packages_for_db {
- tx.execute(
- "INSERT INTO artifact (digest, size, path, signature_path, build_log_path, build_id, created_at)
- VALUES (?1,?2,?3,?4,?5,?6,?7)
- ON CONFLICT(digest) DO UPDATE SET build_id=excluded.build_id",
- rusqlite::params![p.digest, p.size as i64, p.path, p.signature_path, log_path, build_id, at],
+ db::insert_artifact_in(
+ tx,
+ &db::NewArtifact {
+ digest: &p.digest,
+ size: p.size as i64,
+ path: &p.path,
+ signature_path: p.signature_path.as_deref(),
+ build_log_path: Some(&log_path),
+ build_id: &build_id,
+ at: &at,
+ },
)?;
}
Ok(())