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/mod.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/mod.rs')
| -rw-r--r-- | src/db/mod.rs | 111 |
1 files changed, 42 insertions, 69 deletions
diff --git a/src/db/mod.rs b/src/db/mod.rs index 4379a5f..27d1bfb 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -29,17 +29,19 @@ mod world; /// no crate-internal alias to keep in a production build. #[cfg(feature = "test-support")] pub use migrations::MIGRATIONS; -pub(crate) use model::StateEnum; /// Its only caller is the test-tier `world_members`, so it is gated with it. #[cfg(feature = "test-support")] pub(crate) use model::json_or; +pub(crate) use model::StateEnum; -pub use model::{ - BUILD_STEPS, BuildState, CandidateRow, CandidateState, - Identity, Recipe, ReleaseRow, - SourceDigest, SourceEntry, StageBCacheRow, StepState, - SubscriptionState, UpstreamPin, WorldMember, candidate_kind, - notice_kind, +pub use audit::{audit, audit_in, audit_system, list_audit, AuditEntry}; +pub use invariants::approved_but_unbuilt; +#[cfg(feature = "test-support")] +pub use invariants::unapproved_index_entries; +pub use metrics::{ + artifact_bytes_served, build_state_counts, count_index_packages, count_pending_reviews, count_published_releases, + count_subscriptions, count_unacknowledged_notices, last_gc_age_secs, last_poll_age_secs, oldest_queued_age_secs, + pending_review_ages_secs, }; /// `ReleaseState` is a column type on the release row. Nothing outside `db` /// names it, so the alias out of `db` exists only for the test tier. @@ -47,53 +49,42 @@ pub use model::{ pub use model::ReleaseState; #[cfg(not(feature = "test-support"))] pub(crate) use model::ReleaseState; -pub use audit::{AuditEntry, audit, audit_in, audit_system, list_audit}; -pub use invariants::approved_but_unbuilt; -#[cfg(feature = "test-support")] -pub use invariants::unapproved_index_entries; -pub use metrics::{ - artifact_bytes_served, build_state_counts, count_index_packages, count_pending_reviews, - count_published_releases, count_subscriptions, count_unacknowledged_notices, last_gc_age_secs, - last_poll_age_secs, oldest_queued_age_secs, pending_review_ages_secs, +pub use model::{ + candidate_kind, notice_kind, BuildState, CandidateRow, CandidateState, Identity, Recipe, ReleaseRow, SourceDigest, + SourceEntry, StageBCacheRow, StepState, SubscriptionState, UpstreamPin, WorldMember, BUILD_STEPS, }; pub use notices::{acknowledge_notice, list_notices, put_notice_once}; pub use packages::{ - accepted_recipe, builds_for_pkgbase, index_artifact, index_packages, - index_version, our_package_names, -}; -pub use pkgbases::{ - Pkgbase, accepted_release_for, get_pkgbase, get_pkgbase_by_id, set_aur_head, + accepted_recipe, builds_for_pkgbase, index_artifact, index_packages, index_version, our_package_names, }; #[cfg(feature = "test-support")] pub use pkgbases::cas_accepted_release; +pub use pkgbases::{accepted_release_for, get_pkgbase, get_pkgbase_by_id, set_aur_head, Pkgbase}; pub use publish_writes::{ - NewRelease, accepted_pointer_in, artifact_path, cas_accepted_release_in, - insert_package_in, insert_release_in, remove_index_packages_in, remove_package_by_name_in, + accepted_pointer_in, artifact_path, cas_accepted_release_in, insert_package_in, insert_release_in, + remove_index_packages_in, remove_package_by_name_in, NewRelease, }; pub use releases::{ - accepted_release, all_published_releases, release_by_id, releases_for_pkgbase, - withdraw_release_in, + accepted_release, all_published_releases, release_by_id, releases_for_pkgbase, withdraw_release_in, }; pub use repos::{ensure_repo, repo_id}; pub use retention::{ - mark_release_purged, pkgbase_release_pointers, published_release_ids, record_gc_run, - release_artifact_paths, serving_release_ids, + mark_release_purged, pkgbase_release_pointers, published_release_ids, record_gc_run, release_artifact_paths, + serving_release_ids, }; -pub use settings::{all_settings, setting, setting_i64}; #[cfg(feature = "test-support")] pub use settings::set_setting; -pub use snapshots::{SnapshotRow, put_snapshot, snapshot_by_id}; +pub use settings::{all_settings, setting, setting_i64}; #[cfg(feature = "test-support")] pub use snapshots::snapshot_by_commit; +pub use snapshots::{put_snapshot, snapshot_by_id, SnapshotRow}; pub use stage_b::{stage_b_cache_get, stage_b_cache_put, stage_b_recent}; pub use staleness::{ - NewArtifact, approval_note, candidate_snapshot_id, index_recipes, - insert_artifact_in, published_world_members, put_source_cache, served_vs_offered_pkgvers, - source_cache_path, + approval_note, candidate_snapshot_id, index_recipes, insert_artifact_in, published_world_members, put_source_cache, + served_vs_offered_pkgvers, source_cache_path, NewArtifact, }; pub use subscriptions::{ - due_subscriptions, get_subscription, list_subscriptions, note_check, - set_subscription_state, subscribe, + due_subscriptions, get_subscription, list_subscriptions, note_check, set_subscription_state, subscribe, }; pub use world::put_world_snapshot; #[cfg(feature = "test-support")] @@ -138,12 +129,11 @@ fn open(path: &Path, read_only: bool) -> Result<Connection> { fn configure(conn: &Connection, read_only: bool) -> Result<()> { conn.pragma_update(None, "journal_mode", "WAL") - .and_then(|_| conn.pragma_update(None, "busy_timeout", 5000)) - .and_then(|_| conn.pragma_update(None, "foreign_keys", "ON")) + .and_then(|()| conn.pragma_update(None, "busy_timeout", 5000)) + .and_then(|()| conn.pragma_update(None, "foreign_keys", "ON")) .map_err(|e| Error::db(e.to_string()))?; if !read_only { - conn.pragma_update(None, "synchronous", "FULL") - .map_err(|e| Error::db(e.to_string()))?; + conn.pragma_update(None, "synchronous", "FULL").map_err(|e| Error::db(e.to_string()))?; } Ok(()) } @@ -151,18 +141,13 @@ fn configure(conn: &Connection, read_only: bool) -> Result<()> { pub fn migrate(path: &Path) -> Result<u32> { let mut conn = open(path, false)?; let mut applied = 0u32; - let current: u32 = conn - .pragma_query_value(None, "user_version", |r| r.get(0)) - .map_err(|e| Error::db(e.to_string()))?; + let current: u32 = + conn.pragma_query_value(None, "user_version", |r| r.get(0)).map_err(|e| Error::db(e.to_string()))?; for m in migrations::MIGRATIONS { if m.version > current { - let tx = conn - .transaction() - .map_err(|e| Error::db(e.to_string()))?; - tx.execute_batch(m.sql) - .map_err(|e| Error::db(format!("migration {} ({}): {e}", m.version, m.name)))?; - tx.pragma_update(None, "user_version", m.version) - .map_err(|e| Error::db(e.to_string()))?; + let tx = conn.transaction().map_err(|e| Error::db(e.to_string()))?; + tx.execute_batch(m.sql).map_err(|e| Error::db(format!("migration {} ({}): {e}", m.version, m.name)))?; + tx.pragma_update(None, "user_version", m.version).map_err(|e| Error::db(e.to_string()))?; tx.commit().map_err(|e| Error::db(e.to_string()))?; applied += 1; } @@ -195,7 +180,7 @@ pub struct Writer { } impl Writer { -/// Only `Writer::open` in this module starts a writer. + /// Only `Writer::open` in this module starts a writer. fn start(path: &Path) -> Result<Self> { let conn = open(path, false)?; let (tx, rx) = unbounded::<Msg>(); @@ -207,7 +192,7 @@ impl Writer { .spawn(move || { let mut conn = conn; alive_thread.store(true, Ordering::SeqCst); - for msg in rx.iter() { + for msg in &rx { match msg { Msg::Call(f) => f(&mut conn), #[cfg(feature = "test-support")] @@ -237,9 +222,7 @@ impl Writer { self.send(Box::new(move |conn| { let _ = reply_tx.send(f(conn)); }))?; - reply_rx - .recv() - .map_err(|_| Error::db("writer actor gone"))? + reply_rx.recv().map_err(|_| Error::db("writer actor gone"))? } pub(crate) fn tx<T>( @@ -263,9 +246,7 @@ impl Writer { if !self.is_alive() { return Err(Error::db("writer actor gone")); } - self.tx - .send(Msg::Call(f)) - .map_err(|_| Error::db("writer actor gone")) + self.tx.send(Msg::Call(f)).map_err(|_| Error::db("writer actor gone")) } /// Stop the writer actor. @@ -273,7 +254,7 @@ impl Writer { /// Test-tier only: the server runs until the process ends and never /// quiesces the writer deliberately. Tests use it to prove a worker /// that dies mid-write leaves the database consistent. -#[cfg(feature = "test-support")] + #[cfg(feature = "test-support")] pub fn shutdown(&self) { let _ = self.tx.send(Msg::Shutdown); } @@ -312,10 +293,7 @@ impl Readers { if pool.iter().position(|(p, _)| p == &path).is_none() { pool.push((path.clone(), open(&path, true)?)); } - let idx = pool - .iter() - .position(|(p, _)| p == &path) - .ok_or_else(|| Error::db("reader pool lost entry"))?; + let idx = pool.iter().position(|(p, _)| p == &path).ok_or_else(|| Error::db("reader pool lost entry"))?; // We only ever use one connection at a time per thread, and `f` // receives &Connection rather than &Readers, so it cannot re-enter. let conn = &pool[idx].1; @@ -338,10 +316,7 @@ impl Db { } pub fn open_migrated(path: &Path) -> Result<Self> { - Ok(Self { - writer: Arc::new(Writer::start(path)?), - readers: Arc::new(Readers::new(path)), - }) + Ok(Self { writer: Arc::new(Writer::start(path)?), readers: Arc::new(Readers::new(path)) }) } pub fn read<T>(&self, f: impl FnOnce(&Connection) -> Result<T>) -> Result<T> { @@ -352,16 +327,14 @@ impl Db { pub fn backup_to(writer: &Writer, dest: &Path) -> Result<()> { let dest_s = dest.display().to_string(); writer.call(move |conn| { - conn.execute("VACUUM INTO ?1", rusqlite::params![dest_s]) - .map_err(|e| Error::db(e.to_string()))?; + conn.execute("VACUUM INTO ?1", rusqlite::params![dest_s]).map_err(|e| Error::db(e.to_string()))?; Ok(()) }) } pub fn schema_version(path: &Path) -> Result<i64> { - let conn = rusqlite::Connection::open(path) - .map_err(|e| Error::db(format!("{} does not open: {e}", path.display())))?; + let conn = + rusqlite::Connection::open(path).map_err(|e| Error::db(format!("{} does not open: {e}", path.display())))?; conn.query_row("PRAGMA user_version", [], |r| r.get(0)) .map_err(|e| Error::db(format!("{} has no schema version: {e}", path.display()))) } - |
