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/watch/detect.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/watch/detect.rs')
| -rw-r--r-- | src/watch/detect.rs | 71 |
1 files changed, 27 insertions, 44 deletions
diff --git a/src/watch/detect.rs b/src/watch/detect.rs index 1c72131..d51ca03 100644 --- a/src/watch/detect.rs +++ b/src/watch/detect.rs @@ -1,5 +1,8 @@ use crate::config::Config; -use crate::db::{self, *}; +use crate::db::{ + self, get_pkgbase, notice_kind, Db, Identity, Pkgbase, Recipe, ReleaseRow, SourceDigest, SubscriptionState, + UpstreamPin, +}; use crate::error::{Missing, Result}; use crate::pkgver; use crate::recipe::recipe_from_tree; @@ -31,10 +34,10 @@ pub struct CheckReport { } pub fn check_pkgbase(cfg: &Config, db: &Db, name: &str) -> Result<CheckReport> { - let pb = get_pkgbase(db, name)? - .ok_or_else(|| crate::error::Error::not_found(Missing::Pkgbase(name.to_string())))?; + let pb = + get_pkgbase(db, name)?.ok_or_else(|| crate::error::Error::not_found(Missing::Pkgbase(name.to_string())))?; let sub = db::get_subscription(db, name)?; - let paused = sub.as_ref().map(|s| s.state == SubscriptionState::Paused).unwrap_or(false); + let paused = sub.as_ref().is_some_and(|s| s.state == SubscriptionState::Paused); if paused { return Ok(CheckReport { pkgbase: name.into(), head: String::new(), outcome: Outcome::Paused }); } @@ -46,7 +49,7 @@ pub fn check_pkgbase(cfg: &Config, db: &Db, name: &str) -> Result<CheckReport> { pb.id, notice_kind::DELETED, "high", - serde_json::json!({"aur_url": pb.aur_url, "note": "repository no longer exists"}), + &serde_json::json!({"aur_url": pb.aur_url, "note": "repository no longer exists"}), )?; db::set_subscription_state(&db.writer, name, SubscriptionState::Orphaned)?; return Ok(CheckReport { pkgbase: name.into(), head: String::new(), outcome: Outcome::Gone }); @@ -77,12 +80,9 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result<CheckRepor pb.id, notice_kind::DELETED, "high", - serde_json::json!({"mirror_divergence": a.aur_commit}), + &serde_json::json!({"mirror_divergence": a.aur_commit}), )?; - return Ok(report(Outcome::Blocked(format!( - "accepted pin {} missing from local mirror", - a.aur_commit - )))); + return Ok(report(Outcome::Blocked(format!("accepted pin {} missing from local mirror", a.aur_commit)))); } } @@ -90,13 +90,9 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result<CheckRepor let recipe = recipe_from_tree(&tree.files)?; let recipe_hash = tree.recipe_hash(); - let has_vcs = recipe.source_entries.iter().any(|e| e.is_vcs()); - let accepted_pins: Vec<UpstreamPin> = accepted.as_ref().map(|a| a.pins()).unwrap_or_default(); - let stage_a = if has_vcs { - Some(crate::watch::upstream::probe(&recipe, &accepted_pins)?) - } else { - None - }; + let has_vcs = recipe.source_entries.iter().any(super::super::db::model::SourceEntry::is_vcs); + let accepted_pins: Vec<UpstreamPin> = accepted.as_ref().map_or_default(super::super::db::model::ReleaseRow::pins); + let stage_a = if has_vcs { Some(crate::watch::upstream::probe(&recipe, &accepted_pins)?) } else { None }; let resolved = if !has_vcs { None } else if stage_a.as_ref().unwrap().needs_stage_b() { @@ -124,14 +120,8 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result<CheckRepor source_digests: digests.clone(), }; let identity_hash = identity.hash()?; - let snap_id = db::put_snapshot( - &db.writer, - pb.id, - head, - &recipe_hash, - &serde_json::to_string(&recipe)?, - &tree.json_list(), - )?; + let snap_id = + db::put_snapshot(&db.writer, pb.id, head, &recipe_hash, &serde_json::to_string(&recipe)?, &tree.json_list())?; let nc = NewCandidate { snapshot_id: snap_id, @@ -171,7 +161,7 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result<CheckRepor pb.id, notice_kind::DOWNGRADE, "warning", - serde_json::json!({"served": base.version(), "aur": new_version}), + &serde_json::json!({"served": base.version(), "aur": new_version}), )?; } @@ -189,21 +179,11 @@ fn outcome_of(up: Upsert) -> Outcome { } } -fn non_publishable( - db: &Db, - pb: &Pkgbase, - base: &ReleaseRow, - nc: &NewCandidate, - recipe: &Recipe, -) -> Result<Outcome> { +fn non_publishable(db: &Db, pb: &Pkgbase, base: &ReleaseRow, nc: &NewCandidate, recipe: &Recipe) -> Result<Outcome> { let old_digests: Vec<SourceDigest> = base.digests(); let new_digests: Vec<SourceDigest> = serde_json::from_str(&nc.source_digests_json).unwrap_or_default(); - let vcs_indices: std::collections::BTreeSet<usize> = recipe - .source_entries - .iter() - .filter(|e| e.is_vcs()) - .map(|e| e.index) - .collect(); + let vcs_indices: std::collections::BTreeSet<usize> = + recipe.source_entries.iter().filter(|e| e.is_vcs()).map(|e| e.index).collect(); let changed_remote: Vec<&SourceDigest> = new_digests .iter() .filter(|n| n.kind != "local" && !vcs_indices.contains(&n.index)) @@ -223,7 +203,7 @@ fn non_publishable( .map(|n| { serde_json::json!({"index": n.index, "url": n.url, "old": old_digests.iter().find(|o| o.index == n.index) - .map(|o| o.digest.clone()).unwrap_or_default(), + .map_or_default(|o| o.digest.clone()), "new": n.digest}) }) .collect(); @@ -232,13 +212,16 @@ fn non_publishable( pb.id, notice_kind::INTEGRITY_ALERT, "high", - serde_json::json!({ + &serde_json::json!({ "version": nc.version(), "changed": changed, "message": "the artifact in your index was built from bytes upstream no longer serves; the version string is unchanged", }), )?; - return Ok(Outcome::Notice { kind: notice_kind::INTEGRITY_ALERT.into(), detail: serde_json::json!({"changed": changed}) }); + return Ok(Outcome::Notice { + kind: notice_kind::INTEGRITY_ALERT.into(), + detail: serde_json::json!({"changed": changed}), + }); } if pins_changed { db::put_notice_once( @@ -246,7 +229,7 @@ fn non_publishable( pb.id, notice_kind::PIN_DRIFT, "info", - serde_json::json!({ + &serde_json::json!({ "version": nc.version(), "message": "upstream moved; pkgver unchanged, nothing publishable", }), @@ -258,7 +241,7 @@ fn non_publishable( pb.id, notice_kind::RECIPE_DRIFT, "warning", - serde_json::json!({ + &serde_json::json!({ "version": nc.version(), "accepted_aur_commit": base.aur_commit, "aur_commit": "moved", |
