diff options
| author | aur-build <aur-build@localhost> | 2026-11-20 23:38:01 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-20 23:38:01 +0000 |
| commit | c295510e2bb0ee61234536c832dad87a45977fc8 (patch) | |
| tree | d9e73e141da7eb2b09e553998a1435ad023cc0ac /src/ops.rs | |
| parent | 92ecaabd7c62d029eba239e95cc8a7d2520fe4a9 (diff) | |
| download | aur-build-c295510e2bb0ee61234536c832dad87a45977fc8.tar.gz aur-build-c295510e2bb0ee61234536c832dad87a45977fc8.zip | |
sandbox: keep `Exit` out of the release build
`Exit` is the result of running a command in a sandbox. `pipeline` consumes it
through `Sandbox::run` — `.success()`, `.stderr` — without ever writing the name,
which is why the census called it dead outside `sandbox`.
The type now lives in a private `mod exit` and reaches the world through an
alias that is `pub` only under `test-support` and `pub(crate)` otherwise. A
`pub` definition inside a private module is not a nameable path from outside,
but it is visible enough to appear in a public trait signature, which is what
makes this possible where a plain `pub(crate) struct` is not.
Verified with an external crate: naming `aur_build::sandbox::Exit` in a release
build is `error[E0603]: struct Exit is private`; with `test-support` it compiles.
Diffstat (limited to 'src/ops.rs')
| -rw-r--r-- | src/ops.rs | 42 |
1 files changed, 41 insertions, 1 deletions
@@ -43,7 +43,21 @@ pub struct Metrics { } impl Metrics { + /// The metrics report computes it internally; a test checks the arithmetic. + /// + /// Module-internal in a production build, `pub` only under `test-support`: + /// one body behind two visibility declarations, exactly one of which compiles. + #[cfg(feature = "test-support")] pub fn build_success_rate(&self) -> f64 { + Self::build_success_rate_impl(self) + } + + #[cfg(not(feature = "test-support"))] + pub(crate) fn build_success_rate(&self) -> f64 { + Self::build_success_rate_impl(self) + } + + fn build_success_rate_impl(&self) -> f64 { match self.succeeded + self.failed { 0 => 1.0, n => self.succeeded as f64 / n as f64, @@ -307,7 +321,19 @@ pub fn retention(cfg: &Config, db: &Db, keep: Option<usize>) -> Result<Retention Ok(report) } -pub const STAGING_GRACE_SECS: i64 = 3600; +/// How long a file may sit in staging before the sweep considers it abandoned. +/// +/// The value lives once, in a private const, so the two visibility aliases below +/// cannot drift apart. Production reaches the grace period through +/// `run_maintenance`, which is the only thing that sweeps; a test that pins the +/// number is a test, not a caller. +const STAGING_GRACE_SECS_VALUE: i64 = 3600; + +#[cfg(feature = "test-support")] +pub const STAGING_GRACE_SECS: i64 = STAGING_GRACE_SECS_VALUE; + +#[cfg(not(feature = "test-support"))] +pub(crate) const STAGING_GRACE_SECS: i64 = STAGING_GRACE_SECS_VALUE; pub fn release_files(cfg: &Config, db: &Db, release_id: i64) -> Result<Vec<PathBuf>> { let mut out = Vec::new(); @@ -329,7 +355,21 @@ pub fn release_files(cfg: &Config, db: &Db, release_id: i64) -> Result<Vec<PathB Ok(out) } +/// The maintenance pass calls it; a test pins what it sweeps without running the whole pass. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn sweep_staging(cfg: &Config, db: &Db, grace_secs: i64) -> Result<(usize, u64)> { + sweep_staging_impl(cfg, db, grace_secs) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn sweep_staging(cfg: &Config, db: &Db, grace_secs: i64) -> Result<(usize, u64)> { + sweep_staging_impl(cfg, db, grace_secs) +} + +fn sweep_staging_impl(cfg: &Config, db: &Db, grace_secs: i64) -> Result<(usize, u64)> { let root = cfg.staging_dir(); let Ok(entries) = std::fs::read_dir(&root) else { return Ok((0, 0)) }; let now = time::now(); |
