summaryrefslogtreecommitdiffstats
path: root/src/db/model.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-19 17:33:17 +0000
committeraur-build <aur-build@localhost>2026-11-19 17:33:17 +0000
commit4304b0f336ddba7b4ec6780795059ff2066d105b (patch)
tree10edea744a1c2bf3fc363b4dc7f64abac8b1a0d3 /src/db/model.rs
parente757979f1a2afdbe7146066345bb9acd19d3b151 (diff)
downloadaur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.tar.gz
aur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.zip
comments: keep only what the code cannot show
Stripped every comment that described what an item does, documented its arguments or fields, or cited the design docs (§n, I-n, m-n, decision n). 2247 comments down to 83. What survives: the section dividers that segment the large modules, the secret-handling warnings, the agent wire-frame directions, and the few notes without which the code they attach to reads as redundant, reorderable, or unsound.
Diffstat (limited to 'src/db/model.rs')
-rw-r--r--src/db/model.rs91
1 files changed, 0 insertions, 91 deletions
diff --git a/src/db/model.rs b/src/db/model.rs
index 84701d1..5afb793 100644
--- a/src/db/model.rs
+++ b/src/db/model.rs
@@ -2,24 +2,15 @@ use serde::{Deserialize, Serialize};
use crate::hash;
-/// One resolved upstream VCS source (DESIGN.md §3). The commit SHA alone is
-/// sufficient: a git commit transitively commits to its tree, and a gitlink in
-/// that tree commits to any submodule's commit.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct UpstreamPin {
pub index: usize,
pub url: String,
- /// The ref we asked for: `HEAD`, a tag, or an explicit commit.
pub ref_: String,
pub branch: Option<String>,
- /// The pin.
pub commit: String,
}
-/// A row of the Stage B cache (§5.2): the version resolution produced, with the
-/// pins it was computed from. This lives with the schema because the table does —
-/// the persistence layer must not name a type from the module that owns VCS
-/// probing (§6 M-6).
#[derive(Debug, Clone)]
pub struct StageBCacheRow {
pub epoch: String,
@@ -34,40 +25,28 @@ impl StageBCacheRow {
}
}
-/// A source entry with the digest *we* computed, regardless of what the
-/// PKGBUILD declares (§5.3).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SourceDigest {
pub index: usize,
pub url: String,
- /// `static` | `vcs` | `local`
pub kind: String,
- /// sha256, or the resolved VCS commit for vcs sources.
pub digest: String,
pub size: u64,
- /// True when the PKGBUILD gave us no checksum to trust — `SKIP`, a malformed
- /// digest, or nothing at all. It means that and nothing else (m-19): a `-git`
- /// source has no checksum by design because the *pin* is the integrity. Ask
- /// [`SourceDigest::is_vcs`] which mechanism protects an entry.
pub skip_declared: bool,
}
impl SourceDigest {
- /// True when this entry's integrity comes from a resolved commit rather than a
- /// content hash.
pub fn is_vcs(&self) -> bool {
matches!(self.kind.as_str(), "vcs" | "git" | "svn" | "hg" | "bzr")
}
}
-/// A member of a world snapshot: one of *our* packages the build ran against.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct WorldMember {
pub pkgbase: String,
pub version: String,
}
-/// The identity tuple of a candidate (§3). Every element is part of the key.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Identity {
pub aur_commit: String,
@@ -79,30 +58,18 @@ pub struct Identity {
}
impl Identity {
- /// The hash that makes I3 a fact: two byte-identical inputs never produce two
- /// candidates, and any change to what becomes a byte in the artifact produces a
- /// new one. This is the value an approval must echo; a value that cannot be
- /// serialized is an error rather than a digest, because a shared fallback
- /// digest would be the one way two identities could collide by accident.
pub fn hash(&self) -> crate::error::Result<String> {
Ok(format!("sha256:{}", hash::hex(hash::canonical_json(self)?.as_bytes())))
}
}
-/// The review state machine (§7.1). A decision must never be overwritten by
-/// accident — an approval that silently replaced a rejection would break I2 and
-/// I3 without any symptom — so the states are an enum and
-/// [`crate::db::candidates::resolve_in`] refuses a move the machine forbids.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CandidateState {
- /// The only state a reviewer can act on.
PendingReview,
Approved,
Rejected,
- /// A newer review of the same pkgbase took its place (§7.1).
Superseded,
- /// Not approved because something it needs is missing (§10.4).
Blocked,
}
@@ -133,7 +100,6 @@ impl CandidateState {
*self == CandidateState::PendingReview
}
- /// Re-writing the state a row already has is a no-op, not a move.
pub fn can_transition(&self, to: CandidateState) -> bool {
use CandidateState::*;
if *self == to {
@@ -141,7 +107,6 @@ impl CandidateState {
}
match self {
PendingReview => matches!(to, Approved | Rejected | Superseded | Blocked),
- // A decided review is only ever frozen, never re-decided (§7.1).
Approved | Rejected => to == Superseded,
Blocked => matches!(to, PendingReview | Approved | Rejected),
Superseded => false,
@@ -168,14 +133,11 @@ pub mod candidate_kind {
pub const FIRST_INTRODUCTION: &str = "first_introduction";
}
-/// The release state machine (§9).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ReleaseState {
Published,
- /// Taken out of the index (§9 withdrawal); the row stays (§15).
Withdrawn,
- /// Approved, but the build never produced it: the old version still serves.
FailedUnbuilt,
}
@@ -198,7 +160,6 @@ impl ReleaseState {
ReleaseState::ALL.iter().copied().find(|r| r.as_str() == s)
}
- /// Withdrawal is the only move a release makes on its own.
pub fn can_transition(&self, to: ReleaseState) -> bool {
use ReleaseState::*;
if *self == to {
@@ -217,11 +178,7 @@ impl std::fmt::Display for ReleaseState {
}
}
-/// What the state enums below have in common: a closed set of column values,
-/// parsed where a row is read, so `db::state_col` can fail an unknown state
-/// instead of defaulting it.
pub trait StateEnum: Copy + Sized {
- /// The name of the machine, for the error message.
const KIND: &'static str;
fn parse(text: &str) -> Option<Self>;
fn as_str(&self) -> &'static str;
@@ -247,17 +204,11 @@ impl_state_enum!(StepState, "build step");
impl_state_enum!(ReleaseState, "release");
impl_state_enum!(SubscriptionState, "subscription");
-/// The build state machine (§7.1, §8.2). A state is one of these seven, it is
-/// parsed where a row is read, and `can_transition` is the only way a write
-/// happens.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum BuildState {
Queued,
- /// Claimed by a worker with a lease (§8.2).
Leased,
- /// A step is executing.
Running,
- /// Waiting for packages another build must publish first (§10.4).
BlockedMissingDep,
Succeeded,
Failed,
@@ -275,8 +226,6 @@ impl BuildState {
BuildState::Cancelled,
];
- /// The text in the `state` column — a spelling the reaper, dispatcher and UI
- /// all speak.
pub fn as_str(&self) -> &'static str {
match self {
BuildState::Queued => "queued",
@@ -289,14 +238,10 @@ impl BuildState {
}
}
- /// An unrecognised state is `None`, and the row boundary turns that into an
- /// error: a state we cannot name is one we must not act on.
pub fn parse(s: &str) -> Option<BuildState> {
BuildState::ALL.iter().copied().find(|b| b.as_str() == s)
}
- /// Nothing happens to a finished build by itself; only an explicit human
- /// requeue or resume moves it again.
pub fn is_terminal(&self) -> bool {
matches!(
self,
@@ -304,32 +249,22 @@ impl BuildState {
)
}
- /// Writing the state a row already has is always allowed: the step loop
- /// re-asserts `Running` at every step boundary (§8.3). Everything else is
- /// refused by [`crate::db::builds::set_state`], and the refusals are the point:
- /// nothing revives a `Succeeded` build, and a build reaped back to `Queued`
- /// cannot be completed by the zombie worker that lost its lease.
pub fn can_transition(&self, to: BuildState) -> bool {
use BuildState::*;
if *self == to {
return true;
}
match self {
- // The dispatcher claims queued builds; `aur-build run <id>` runs one
- // in the foreground without a lease.
Queued => matches!(to, Leased | Running | BlockedMissingDep | Cancelled),
Leased => matches!(to, Running | Queued | BlockedMissingDep | Succeeded | Failed | Cancelled),
Running => matches!(to, Queued | BlockedMissingDep | Succeeded | Failed | Cancelled),
BlockedMissingDep => matches!(to, Queued | Cancelled),
- // A failed build is resumed on the same row — that is I5 (§8.4).
Failed => matches!(to, Queued | Running),
Cancelled => to == Queued,
Succeeded => false,
}
}
- /// Every state that may legally move to `to` — the `WHERE state IN (...)`
- /// that makes a state write a compare-and-swap.
pub fn predecessors(to: BuildState) -> Vec<&'static str> {
BuildState::ALL
.iter()
@@ -354,9 +289,6 @@ impl std::fmt::Display for BuildState {
}
}
-/// The step checkpoint state machine (§8.3, I5). The checkpoint row is what a
-/// resumed build reads to decide what not to redo, so a completed checkpoint is
-/// frozen.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum StepState {
@@ -364,7 +296,6 @@ pub enum StepState {
Running,
Succeeded,
Failed,
- /// Killed mid-step; the reaper writes this so the resume re-runs it (§8.2).
Interrupted,
Skipped,
}
@@ -394,8 +325,6 @@ impl StepState {
StepState::ALL.iter().copied().find(|st| st.as_str() == text)
}
- /// I5: the resume skips a step in one of these two states, so nothing may
- /// move it again.
pub fn is_done(&self) -> bool {
matches!(self, StepState::Succeeded | StepState::Skipped)
}
@@ -407,8 +336,6 @@ impl StepState {
}
match self {
Pending => matches!(to, Running | Succeeded | Failed | Interrupted | Skipped),
- // `Running → Pending` is the blocked path: the step did not happen,
- // so the checkpoint goes back to waiting.
Running => matches!(to, Pending | Succeeded | Failed | Interrupted | Skipped),
Failed | Interrupted => matches!(to, Pending | Running),
Succeeded | Skipped => false,
@@ -442,13 +369,11 @@ pub mod notice_kind {
pub const DOWNGRADE: &str = "downgrade";
}
-/// Whether a pkgbase is being watched (§4.1, §12).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SubscriptionState {
Active,
Paused,
- /// The pkgbase left AUR; the watcher stopped looking (§12).
Orphaned,
Removed,
}
@@ -474,8 +399,6 @@ impl SubscriptionState {
SubscriptionState::ALL.iter().copied().find(|st| st.as_str() == text)
}
- /// Pause and resume are the only moves the UI makes; orphaned and removed
- /// are facts about the pkgbase, reported once.
pub fn can_transition(&self, to: SubscriptionState) -> bool {
use SubscriptionState::*;
if *self == to {
@@ -496,8 +419,6 @@ impl std::fmt::Display for SubscriptionState {
}
}
-/// The pipeline steps (§8.1). Order matters: a build resumes at the first step
-/// in this list without a `succeeded` row.
pub const BUILD_STEPS: &[&str] = &[
"materialize",
"plan",
@@ -511,20 +432,15 @@ pub const BUILD_STEPS: &[&str] = &[
"publish",
];
-/// A `source=()` entry after parsing.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SourceEntry {
pub index: usize,
- /// The URL as written, minus the filename fragment.
pub url: String,
- /// Explicit filename (`::name` / `::` prefix handling).
pub filename: Option<String>,
pub commit: Option<String>,
pub tag: Option<String>,
pub branch: Option<String>,
- /// Set when the url is prefixed `git+`, `svn+`, `hg+`, `bzr+`.
pub vcs: Option<String>,
- /// True for files shipped inside the AUR repo (no scheme).
pub local: bool,
}
@@ -534,7 +450,6 @@ impl SourceEntry {
}
}
-/// A parsed recipe: what `.SRCINFO` / `PKGBUILD` tell us.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Recipe {
pub pkgbase: String,
@@ -559,15 +474,11 @@ pub struct Recipe {
pub options: Vec<String>,
pub backup: Vec<String>,
pub install: Option<String>,
- /// Names of the binary packages this pkgbase emits (split pkgbases have N).
pub pkgnames: Vec<String>,
pub pkg_depends: Vec<(String, Vec<String>)>,
- /// Raw PKGBUILD text, for display and diffing.
pub pkgbuild: String,
pub srcinfo: Option<String>,
- /// True if `--skippgpcheck` appears in the PKGBUILD.
pub skipgpcheck: bool,
- /// Derived from `source`, so not serialized.
#[serde(skip, default)]
pub source_entries: Vec<SourceEntry>,
}
@@ -578,7 +489,6 @@ impl Recipe {
}
}
-/// A source row as stored on a candidate/release.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseRow {
pub id: i64,
@@ -652,7 +562,6 @@ impl CandidateRow {
}
}
-/// Parse a JSON column with a fallback, so one bad row never takes down a page.
pub fn json_or<T: serde::de::DeserializeOwned>(s: &str, fallback: T) -> T {
serde_json::from_str(s).unwrap_or(fallback)
}