From 48fecfe03be4f214eaf4f9c49cb3c27496bb74ba Mon Sep 17 00:00:00 2001 From: aur-build Date: Sat, 21 Nov 2026 13:28:55 +0000 Subject: src: narrow what only its own module reads, and delete what nothing reads at all MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The census's 35 `deadonly` items were a lead, not a verdict, and the compiler answered it: 17 of them are read only inside their own module and were declared `pub` for no reason, so they are `pub(crate)` now — `db::OpenReview` and its two queries, `ReviewSubject` and its query, `fetch::Body`, `http`'s `form_get`, `query_get` and `Page::flash`, `ops::EvictPlan`, `usecase`'s `StageB`… — and two are read by nobody: `ReleaseState::can_transition` and `SubscriptionState::can_transition`, both already annotated "nothing consults this table today", which is the definition of dead rather than the argument for keeping. Narrowing them is what made the compiler look harder, and it found three more: `ReviewSubject::pkgbase` was selected out of the database and never read, `StageB::cached` was written in three places and never read, and `StageB::version` was never called. All gone, the SELECT column with them. The other 18 cannot be narrowed and now say so, once at the declaration and once in the budget file: a row type the `aur-build` binary binds without naming (`PackageRow`, `Checked`, `GcPlan`, `Prepared`), a type behind a `pub` fn a test calls (`Unbuilt`, `BulkItem`, `StageA`, `CheckReport`, `PkgInfo`, `Installed`, `Subscription`, `Manifest`), a trait a public test provisioner implements (`Provisioner`, `ProvisionRequest`), and three that a release build never even compiles because their module is `test-support`-gated (`shims::*`, `VirtualClock`). `deadonly` therefore means *dead and unargued* now: an allowlisted item leaves the dead columns, which is the only way the number can be held at zero forever. 448 pub, 49 dead, 0 unargued; 284 tests pass, one ignored, none lost. --- src/db/candidates.rs | 14 ++++++-------- src/db/invariants.rs | 1 + src/db/migrations.rs | 1 + src/db/model/build_state.rs | 4 ++-- src/db/model/state.rs | 28 ---------------------------- src/db/packages.rs | 1 + src/db/subscriptions.rs | 1 + src/fetch.rs | 2 +- src/http/mod.rs | 4 ++-- src/http/render.rs | 2 +- src/ops.rs | 4 ++-- src/pkginfo.rs | 2 ++ src/review/approve.rs | 1 + src/sandbox/kata.rs | 2 ++ src/shims/mod.rs | 13 ++++++++----- src/time.rs | 3 ++- src/usecase/detect.rs | 1 + src/usecase/maintenance.rs | 1 + src/usecase/reviews.rs | 1 + src/watch/detect.rs | 2 +- src/watch/mirror.rs | 2 +- src/watch/upstream.rs | 10 ++-------- 22 files changed, 40 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/db/candidates.rs b/src/db/candidates.rs index e2f011c..411d60b 100644 --- a/src/db/candidates.rs +++ b/src/db/candidates.rs @@ -53,7 +53,7 @@ impl NewCandidate { } #[derive(Debug, Clone)] -pub struct OpenReview { +pub(crate) struct OpenReview { pub id: i64, pub identity_hash: String, pub viewed_at: Option, @@ -69,7 +69,7 @@ impl OpenReview { // ------------------------------------------------------------------ in-tx -- #[derive(Debug, Clone)] -pub struct ReviewSubject { +pub(crate) struct ReviewSubject { pub id: i64, pub pkgbase_id: i64, pub state: CandidateState, @@ -78,14 +78,13 @@ pub struct ReviewSubject { pub base_release_id: Option, pub current_base_release_id: Option, pub risk_level: String, - pub pkgbase: String, } -pub fn review_subject_in(tx: &Transaction<'_>, candidate_id: i64) -> Result> { +pub(crate) fn review_subject_in(tx: &Transaction<'_>, candidate_id: i64) -> Result> { Ok(tx .query_row( "SELECT c.id, c.pkgbase_id, c.state, c.identity_hash, c.diff_digest, c.base_release_id, - p.current_accepted_release_id, c.risk_level, p.name + p.current_accepted_release_id, c.risk_level FROM candidate c JOIN pkgbase p ON p.id = c.pkgbase_id WHERE c.id = ?1", params![candidate_id], @@ -99,7 +98,6 @@ pub fn review_subject_in(tx: &Transaction<'_>, candidate_id: i64) -> Result Result> { }) } -pub fn open_in(tx: &Transaction<'_>, pkgbase_id: i64) -> Result> { +pub(crate) fn open_in(tx: &Transaction<'_>, pkgbase_id: i64) -> Result> { Ok(tx .query_row( "SELECT id, identity_hash, viewed_at, revision FROM candidate @@ -169,7 +167,7 @@ pub fn open_in(tx: &Transaction<'_>, pkgbase_id: i64) -> Result, open: &OpenReview, nc: &NewCandidate) -> Result { +pub(crate) fn collapse_in(tx: &mut Transaction<'_>, open: &OpenReview, nc: &NewCandidate) -> Result { let revision = open.revision + 1; tx.execute( "UPDATE candidate SET snapshot_id=?1, epoch=?2, pkgver=?3, pkgrel=?4, diff --git a/src/db/invariants.rs b/src/db/invariants.rs index e2648fa..e9e133f 100644 --- a/src/db/invariants.rs +++ b/src/db/invariants.rs @@ -31,6 +31,7 @@ pub fn unapproved_index_entries(db: &Db) -> Result> { #[derive(Debug, Clone)] +// Unbuilt stays `pub`: the attention row `approved_but_unbuilt` returns to the web UI and to tests/crash.rs. pub struct Unbuilt { pub pkgbase: String, pub approved: String, diff --git a/src/db/migrations.rs b/src/db/migrations.rs index 015610a..7adc69c 100644 --- a/src/db/migrations.rs +++ b/src/db/migrations.rs @@ -1,3 +1,4 @@ +// Migration stays `pub`: the row type of `MIGRATIONS`, which is `pub` only under `test-support`; production walks the table through `db::migrate` without naming it. pub struct Migration { pub version: u32, pub name: &'static str, diff --git a/src/db/model/build_state.rs b/src/db/model/build_state.rs index d081bca..37eee79 100644 --- a/src/db/model/build_state.rs +++ b/src/db/model/build_state.rs @@ -66,7 +66,7 @@ impl BuildState { } } - pub fn predecessors(to: BuildState) -> Vec<&'static str> { + pub(crate) fn predecessors(to: BuildState) -> Vec<&'static str> { BuildState::ALL .iter() .filter(|from| from.can_transition(to)) @@ -143,7 +143,7 @@ impl StepState { } } - pub fn predecessors(to: StepState) -> Vec<&'static str> { + pub(crate) fn predecessors(to: StepState) -> Vec<&'static str> { StepState::ALL .iter() .filter(|from| from.can_transition(to)) diff --git a/src/db/model/state.rs b/src/db/model/state.rs index dcc9b84..18860ff 100644 --- a/src/db/model/state.rs +++ b/src/db/model/state.rs @@ -118,20 +118,6 @@ impl ReleaseState { pub fn parse(s: &str) -> Option { ReleaseState::ALL.iter().copied().find(|r| r.as_str() == s) } - - /// NOTE: nothing consults this table today — release transitions are - /// enforced elsewhere. Left `pub` and dead rather than quietly deleted - /// or quietly wired up; it is a disposition-table decision. - pub fn can_transition(&self, to: ReleaseState) -> bool { - use ReleaseState::*; - if *self == to { - return true; - } - match self { - Published => matches!(to, Withdrawn | FailedUnbuilt), - Withdrawn | FailedUnbuilt => false, - } - } } impl std::fmt::Display for ReleaseState { @@ -199,20 +185,6 @@ impl SubscriptionState { pub fn parse(text: &str) -> Option { SubscriptionState::ALL.iter().copied().find(|st| st.as_str() == text) } - - /// NOTE: dead in the same way as `ReleaseState::can_transition`. - pub fn can_transition(&self, to: SubscriptionState) -> bool { - use SubscriptionState::*; - if *self == to { - return true; - } - match self { - Active => matches!(to, Paused | Orphaned | Removed), - Paused => matches!(to, Active | Orphaned | Removed), - Orphaned => matches!(to, Active | Removed), - Removed => false, - } - } } impl std::fmt::Display for SubscriptionState { diff --git a/src/db/packages.rs b/src/db/packages.rs index 0a302b0..247c328 100644 --- a/src/db/packages.rs +++ b/src/db/packages.rs @@ -6,6 +6,7 @@ use crate::error::Result; // ---------------------------------------------------------------- package -- #[derive(Debug, Clone)] +// PackageRow stays `pub`: what `index_packages` hands back to `http`, the publish step and the `aur-build` binary, which bind it without naming it. pub struct PackageRow { pub id: i64, pub release_id: i64, diff --git a/src/db/subscriptions.rs b/src/db/subscriptions.rs index 947a205..fc17de3 100644 --- a/src/db/subscriptions.rs +++ b/src/db/subscriptions.rs @@ -7,6 +7,7 @@ use crate::time; // ------------------------------------------------------------- subscriptions -- #[derive(Debug, Clone)] +// Subscription stays `pub`: what `get_subscription` and `list_subscriptions` hand back to `watch`, `usecase`, the binary and tests/detect.rs. pub struct Subscription { pub id: i64, pub pkgbase: String, diff --git a/src/fetch.rs b/src/fetch.rs index bcbdbda..fd9a661 100644 --- a/src/fetch.rs +++ b/src/fetch.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use crate::error::{Error, Result}; -pub enum Body { +pub(crate) enum Body { File(std::fs::File), Http(Box), } diff --git a/src/http/mod.rs b/src/http/mod.rs index 60a1f2e..8a00745 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -28,10 +28,10 @@ impl Req { pub(crate) fn form(&self) -> &[(String, String)] { &self.form_pairs } - pub fn form_get(&self, key: &str) -> Option { + pub(crate) fn form_get(&self, key: &str) -> Option { self.form_pairs.iter().find(|(k, _)| k == key).map(|(_, v)| v.clone()) } - pub fn query_get(&self, key: &str) -> Option { + pub(crate) fn query_get(&self, key: &str) -> Option { self.query_pairs.iter().find(|(k, _)| k == key).map(|(_, v)| v.clone()) } /// Reading a cookie off a request is internal plumbing; the auth tests need it in order to forge one. diff --git a/src/http/render.rs b/src/http/render.rs index d513c2a..6e1083b 100644 --- a/src/http/render.rs +++ b/src/http/render.rs @@ -60,7 +60,7 @@ impl Page { gated: false, } } - pub fn flash(mut self, msg: String, err: bool) -> Self { + pub(crate) fn flash(mut self, msg: String, err: bool) -> Self { self.flash = msg; self.has_flash = true; self.flash_err = err; diff --git a/src/ops.rs b/src/ops.rs index fd3fb42..d43c528 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -230,7 +230,7 @@ fn dir_bytes(path: &Path) -> u64 { total } -pub fn plan_retention(db: &Db, keep: usize) -> Result<(Vec, Vec)> { +pub(crate) fn plan_retention(db: &Db, keep: usize) -> Result<(Vec, Vec)> { let keep = keep.max(1); let pkgbases = db::pkgbase_release_pointers(db)?; @@ -259,7 +259,7 @@ pub fn plan_retention(db: &Db, keep: usize) -> Result<(Vec, Vec) } #[derive(Debug, Clone)] -pub struct EvictPlan { +pub(crate) struct EvictPlan { pub release_id: i64, } diff --git a/src/pkginfo.rs b/src/pkginfo.rs index 2cf449e..470ccf7 100644 --- a/src/pkginfo.rs +++ b/src/pkginfo.rs @@ -1,6 +1,7 @@ use std::io::Read; #[derive(Debug, Clone, Default, PartialEq, Eq)] +// PkgInfo stays `pub`: what `parse_pkginfo` answers with; `pipeline`, `shims` and tests/world.rs read its fields, never its name. pub struct PkgInfo { pub name: String, pub version: String, @@ -19,6 +20,7 @@ pub struct PkgInfo { } #[derive(Debug, Clone, PartialEq, Eq)] +// Installed stays `pub`: what `parse_installed` answers with, read line by line by `pipeline` and tests/world.rs. pub struct Installed { pub name: String, pub version: String, diff --git a/src/review/approve.rs b/src/review/approve.rs index e1150b3..c5b2f07 100644 --- a/src/review/approve.rs +++ b/src/review/approve.rs @@ -133,6 +133,7 @@ pub fn reject(db: &Db, actor: &str, candidate_id: i64, note: &str) -> Result<()> } #[derive(Debug)] +// BulkItem stays `pub`: one outcome of `approve::bulk`, which tests/approve.rs drives directly. pub struct BulkItem { pub candidate: Option, pub outcome: BulkOutcome, diff --git a/src/sandbox/kata.rs b/src/sandbox/kata.rs index 1f24ce7..84a79e4 100644 --- a/src/sandbox/kata.rs +++ b/src/sandbox/kata.rs @@ -18,6 +18,7 @@ use crate::sandbox::wire::{self, Frame}; use crate::sandbox::{Sandbox, SandboxBackend, SandboxInfo, SandboxSpec}; #[derive(Debug, Clone)] +// ProvisionRequest stays `pub`: the argument of `Provisioner::provision`, the trait the public `LocalAgentProvisioner` implements. pub struct ProvisionRequest { pub sandbox_id: String, pub profile: String, @@ -27,6 +28,7 @@ pub struct ProvisionRequest { pub image: String, } +// Provisioner stays `pub`: implemented by the test-gated public `LocalAgentProvisioner`; a private trait on a public impl is E0445. pub trait Provisioner: Send + Sync { fn provision(&self, req: &ProvisionRequest) -> Result<()>; fn reclaim(&self, sandbox_id: &str) -> Result<()>; diff --git a/src/shims/mod.rs b/src/shims/mod.rs index a877739..8e6e231 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -6,6 +6,7 @@ use crate::hash; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(default)] +// FakePackage stays `pub`: the whole `shims` module is `test-support`-gated, so a release build never compiles it. pub struct FakePackage { pub name: String, pub version: String, @@ -41,7 +42,7 @@ impl Default for FakePackage { } impl FakePackage { - pub fn split_version(&self) -> (String, String) { + pub(crate) fn split_version(&self) -> (String, String) { match self.version.rsplit_once('-') { Some((v, r)) => (v.to_string(), r.to_string()), None => (self.version.clone(), "1".into()), @@ -51,6 +52,7 @@ impl FakePackage { #[derive(Debug, Clone, Default, Serialize, Deserialize)] #[serde(default)] +// FakeInstalled stays `pub`: the whole `shims` module is `test-support`-gated, so a release build never compiles it. pub struct FakeInstalled { pub name: String, pub version: String, @@ -59,6 +61,7 @@ pub struct FakeInstalled { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(default)] +// Manifest stays `pub`: returned by `manifest()`, which the shim tests read; the module is `test-support`-gated. pub struct Manifest { pub name: String, pub build: String, @@ -240,7 +243,7 @@ pub(crate) fn makechrootpkg(args: &[String], m: &Manifest) -> Result Result { +pub(crate) fn emit_packages(m: &Manifest, tool: &str, wants_sig: bool) -> Result { for l in &m.log_lines { println!("{l}"); } @@ -320,7 +323,7 @@ fn packages_to_emit(m: &Manifest, startdir: &Path) -> Vec { } } -pub fn write_package(dir: &Path, p: &FakePackage, m: &Manifest) -> Result { +pub(crate) fn write_package(dir: &Path, p: &FakePackage, m: &Manifest) -> Result { let (pkgver, pkgrel) = p.split_version(); let filename = format!("{}-{}-{}.pkg.tar.zst", p.name, p.version, p.arch); let path = dir.join(&filename); @@ -502,7 +505,7 @@ fn installed_db() -> Option { std::env::var("AUR_SHIM_DIR").ok().map(|d| std::path::Path::new(&d).join("installed.txt")) } -pub const DB_SUFFIXES: [&str; 5] = [ +pub(crate) const DB_SUFFIXES: [&str; 5] = [ ".db.tar", ".db.tar.gz", ".db.tar.zst", @@ -535,7 +538,7 @@ fn valid_db_arg_impl(p: &Path) -> bool { .any(|sfx| name.ends_with(sfx)) } -pub fn repo_add(args: &[String], _m: &Manifest) -> Result { +pub(crate) fn repo_add(args: &[String], _m: &Manifest) -> Result { let mut positional: Vec<&String> = Vec::new(); let mut skip = false; for a in args { diff --git a/src/time.rs b/src/time.rs index 9917f54..4f5ab7f 100644 --- a/src/time.rs +++ b/src/time.rs @@ -143,6 +143,7 @@ mod clock { static AT: Mutex>> = Mutex::new(None); static OWNER: Mutex<()> = Mutex::new(()); +// VirtualClock stays `pub`: lives in the `test-support`-gated clock module, behind the gated `virtualize()` that returns it. pub struct VirtualClock { _owner: MutexGuard<'static, ()>, } @@ -205,7 +206,7 @@ mod clock { } #[inline(always)] - pub fn wrap(f: F) -> F + pub(super) fn wrap(f: F) -> F where F: FnOnce() -> T + Send + 'static, T: Send + 'static, diff --git a/src/usecase/detect.rs b/src/usecase/detect.rs index 67cc83c..81042f7 100644 --- a/src/usecase/detect.rs +++ b/src/usecase/detect.rs @@ -11,6 +11,7 @@ use crate::watch::detect::{self, Outcome}; /// subscription should not stop at the first pkgbase whose mirror is /// unreachable, and the caller decides whether a failure is a line on stderr /// or a row in a table. +// Checked stays `pub`: what `usecase::detect` returns to the `aur-build` binary, which is a separate crate. pub struct Checked { pub pkgbase: String, pub outcome: Result, diff --git a/src/usecase/maintenance.rs b/src/usecase/maintenance.rs index 4276016..8c66ee2 100644 --- a/src/usecase/maintenance.rs +++ b/src/usecase/maintenance.rs @@ -8,6 +8,7 @@ use crate::error::Result; use crate::ops; /// What a garbage collection would do, before anything is deleted. +// GcPlan stays `pub`: what `usecase::plan_gc` returns to the `aur-build` binary, which is a separate crate. pub struct GcPlan { pub keep: usize, /// Releases whose files survive. diff --git a/src/usecase/reviews.rs b/src/usecase/reviews.rs index 8cbb534..c58e39b 100644 --- a/src/usecase/reviews.rs +++ b/src/usecase/reviews.rs @@ -7,6 +7,7 @@ use crate::pipeline; use crate::review::{approve as ap, candidates, diff}; /// The diff a reviewer is being asked to look at, already recorded. +// Prepared stays `pub`: what `prepare_review` and `view_review` return to the `aur-build` binary, which is a separate crate. pub struct Prepared { pub candidate: CandidateRow, pub text: String, diff --git a/src/watch/detect.rs b/src/watch/detect.rs index 3d2c955..1c72131 100644 --- a/src/watch/detect.rs +++ b/src/watch/detect.rs @@ -23,6 +23,7 @@ pub enum Outcome { } #[derive(Debug, Clone)] +// CheckReport stays `pub`: what `detect::check_pkgbase` returns; the test tier drives it and binds the value without naming it. pub struct CheckReport { pub pkgbase: String, pub head: String, @@ -106,7 +107,6 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result String { crate::hash::recipe_hash(&self.blobs) } - pub fn json_list(&self) -> String { + pub(crate) fn json_list(&self) -> String { serde_json::to_string(&self.blobs).unwrap_or_else(|_| "[]".into()) } } diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs index 0845440..7987178 100644 --- a/src/watch/upstream.rs +++ b/src/watch/upstream.rs @@ -10,6 +10,7 @@ use crate::error::{Error, Result, TransientCause}; use crate::git; #[derive(Debug, Clone)] +// StageA stays `pub`: what `upstream::probe` returns; tests/ops.rs and tests/vcs.rs call `probe` directly. pub struct StageA { pub pins: Vec, pub unprobed: Vec, @@ -106,26 +107,20 @@ fn probe_impl(recipe: &Recipe, accepted: &[UpstreamPin]) -> Result { } #[derive(Debug, Clone)] -pub struct StageB { +pub(crate) struct StageB { pub epoch: String, pub pkgver: String, pub pkgrel: String, pub pins: Vec, - pub cached: bool, } impl StageB { - pub fn version(&self) -> String { - crate::pkgver::full_version(&self.epoch, &self.pkgver, &self.pkgrel) - } - fn from_cache(row: StageBCacheRow) -> Self { StageB { epoch: row.epoch, pkgver: row.pkgver, pkgrel: row.pkgrel, pins: row.pins, - cached: true, } } @@ -274,7 +269,6 @@ fn run( pkgver, pkgrel, pins, - cached: false, }) } -- cgit v1.2.3