From 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 Mon Sep 17 00:00:00 2001 From: aur-build Date: Sun, 22 Nov 2026 10:36:24 +0000 Subject: 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. --- src/watch/detect.rs | 71 ++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 44 deletions(-) (limited to 'src/watch/detect.rs') 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 { - 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 { 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 Result = 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 = 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 Result Outcome { } } -fn non_publishable( - db: &Db, - pb: &Pkgbase, - base: &ReleaseRow, - nc: &NewCandidate, - recipe: &Recipe, -) -> Result { +fn non_publishable(db: &Db, pb: &Pkgbase, base: &ReleaseRow, nc: &NewCandidate, recipe: &Recipe) -> Result { let old_digests: Vec = base.digests(); let new_digests: Vec = serde_json::from_str(&nc.source_digests_json).unwrap_or_default(); - let vcs_indices: std::collections::BTreeSet = recipe - .source_entries - .iter() - .filter(|e| e.is_vcs()) - .map(|e| e.index) - .collect(); + let vcs_indices: std::collections::BTreeSet = + 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", -- cgit v1.2.3