diff options
| author | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
| commit | 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 (patch) | |
| tree | 7cc7169181b4bdd73fd8817f8c1d7cce6e6998a8 /src/db/releases.rs | |
| parent | 9dc9087d89891c6e5ef7e5dc084dd13c8611843e (diff) | |
| download | aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.tar.gz aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.zip | |
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.
Diffstat (limited to 'src/db/releases.rs')
| -rw-r--r-- | src/db/releases.rs | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/src/db/releases.rs b/src/db/releases.rs index cff31c1..78215cc 100644 --- a/src/db/releases.rs +++ b/src/db/releases.rs @@ -1,6 +1,6 @@ use rusqlite::{params, OptionalExtension, Row}; -use crate::db::*; +use crate::db::{Db, ReleaseRow, ReleaseState}; use crate::error::{Error, Missing, Refused, Result}; // ---------------------------------------------------------------- release -- @@ -32,17 +32,19 @@ const RELEASE_COLS_R: &str = "r.id, r.pkgbase_id, r.candidate_id, r.approval_id, r.world_snapshot_id, r.state, r.published_at"; pub fn withdraw_release_in(tx: &rusqlite::Transaction<'_>, release_id: i64) -> Result<()> { - let n = tx.execute( - "UPDATE release SET state='withdrawn' WHERE id=?1 AND state='published'", - params![release_id], - )?; + let n = + tx.execute("UPDATE release SET state='withdrawn' WHERE id=?1 AND state='published'", params![release_id])?; if n == 0 { - let state: Option<String> = tx - .query_row("SELECT state FROM release WHERE id=?1", params![release_id], |r| r.get(0)) - .optional()?; + let state: Option<String> = + tx.query_row("SELECT state FROM release WHERE id=?1", params![release_id], |r| r.get(0)).optional()?; return Err(match state.as_deref().map(ReleaseState::parse) { None => Error::not_found(Missing::Release(release_id)), - Some(Some(s)) => Error::conflict(Refused::WrongState { entity: "release", id: release_id.to_string(), found: s.to_string(), expected: "published" }), + Some(Some(s)) => Error::conflict(Refused::WrongState { + entity: "release", + id: release_id.to_string(), + found: s.to_string(), + expected: "published", + }), Some(None) => Error::invalid(format!( "release {release_id} has a state outside the state machine: {:?}", state.unwrap_or_default() @@ -55,13 +57,9 @@ pub fn withdraw_release_in(tx: &rusqlite::Transaction<'_>, release_id: i64) -> R pub fn release_by_id(db: &Db, id: i64) -> Result<Option<ReleaseRow>> { db.read(|c| { - c.query_row( - &format!("SELECT {RELEASE_COLS} FROM release WHERE id = ?1"), - params![id], - row_to_release, - ) - .optional() - .map_err(Into::into) + c.query_row(&format!("SELECT {RELEASE_COLS} FROM release WHERE id = ?1"), params![id], row_to_release) + .optional() + .map_err(Into::into) }) } @@ -71,7 +69,8 @@ pub fn accepted_release(db: &Db, pkgbase: &str) -> Result<Option<ReleaseRow>> { &format!( "SELECT {RELEASE_COLS_R} FROM release r JOIN pkgbase p ON p.current_accepted_release_id = r.id - WHERE p.name = ?1 AND r.state = 'published'"), + WHERE p.name = ?1 AND r.state = 'published'" + ), params![pkgbase], row_to_release, ) @@ -82,9 +81,7 @@ pub fn accepted_release(db: &Db, pkgbase: &str) -> Result<Option<ReleaseRow>> { pub fn releases_for_pkgbase(db: &Db, pkgbase_id: i64, limit: i64) -> Result<Vec<ReleaseRow>> { db.read(|c| { - let sql = format!( - "SELECT {RELEASE_COLS} FROM release WHERE pkgbase_id=?1 ORDER BY id DESC LIMIT ?2" - ); + let sql = format!("SELECT {RELEASE_COLS} FROM release WHERE pkgbase_id=?1 ORDER BY id DESC LIMIT ?2"); let mut stmt = c.prepare(&sql)?; let rows = stmt.query_map(params![pkgbase_id, limit], row_to_release)?; let mut out = Vec::new(); @@ -97,9 +94,7 @@ pub fn releases_for_pkgbase(db: &Db, pkgbase_id: i64, limit: i64) -> Result<Vec< pub fn all_published_releases(db: &Db) -> Result<Vec<ReleaseRow>> { db.read(|c| { - let sql = format!( - "SELECT {RELEASE_COLS} FROM release WHERE state='published' ORDER BY pkgbase_id, id DESC" - ); + let sql = format!("SELECT {RELEASE_COLS} FROM release WHERE state='published' ORDER BY pkgbase_id, id DESC"); let mut stmt = c.prepare(&sql)?; let rows = stmt.query_map([], row_to_release)?; let mut out = Vec::new(); @@ -109,4 +104,3 @@ pub fn all_published_releases(db: &Db) -> Result<Vec<ReleaseRow>> { Ok(out) }) } - |
