From c295510e2bb0ee61234536c832dad87a45977fc8 Mon Sep 17 00:00:00 2001 From: aur-build Date: Fri, 20 Nov 2026 23:38:01 +0000 Subject: sandbox: keep `Exit` out of the release build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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. --- src/pipeline/dispatch.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/pipeline/dispatch.rs') diff --git a/src/pipeline/dispatch.rs b/src/pipeline/dispatch.rs index 89a8788..aea934e 100644 --- a/src/pipeline/dispatch.rs +++ b/src/pipeline/dispatch.rs @@ -68,7 +68,21 @@ fn dispatcher(cfg: Arc, db: Db, stop: Arc, tx: Sender) -> Vec { + dispatch_once_impl(cfg, db, tx) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender) -> Vec { + dispatch_once_impl(cfg, db, tx) +} + +fn dispatch_once_impl(cfg: &Config, db: &Db, tx: &Sender) -> Vec { let reaped = builds::reap_expired(db).unwrap_or(0); if reaped > 0 { db::audit_system( @@ -97,7 +111,21 @@ pub fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender) -> Vec ids } +/// Production reaches this through `dispatch_once`, which is the only thing that acts on the answer. +/// +/// 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 admissible(cfg: &Config, db: &Db) -> usize { + admissible_impl(cfg, db) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn admissible(cfg: &Config, db: &Db) -> usize { + admissible_impl(cfg, db) +} + +fn admissible_impl(cfg: &Config, db: &Db) -> usize { let in_flight = builds::in_flight(db).unwrap_or(0) as usize; let slots = cfg.max_concurrent_builds.saturating_sub(in_flight); if slots == 0 { @@ -110,7 +138,21 @@ pub fn admissible(cfg: &Config, db: &Db) -> usize { slots } +/// Production reaches this through `admissible`, which is the only thing that acts on the number. +/// +/// 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 free_disk_mb(path: &std::path::Path) -> u64 { + free_disk_mb_impl(path) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn free_disk_mb(path: &std::path::Path) -> u64 { + free_disk_mb_impl(path) +} + +fn free_disk_mb_impl(path: &std::path::Path) -> u64 { use std::ffi::CString; let c = match CString::new(path.as_os_str().to_string_lossy().as_bytes()) { Ok(c) => c, -- cgit v1.2.3