diff options
| author | dev <dev@localhost> | 2026-11-20 18:49:22 +0000 |
|---|---|---|
| committer | dev <dev@localhost> | 2026-11-20 18:49:22 +0000 |
| commit | 6c4b4394bd8ddf28d130e87e0100349f13f6e912 (patch) | |
| tree | ebba70a9a141d05cb0251663aaacea858ec79115 /src | |
| parent | 895f3547043def08f0822f936ae34458315f6982 (diff) | |
| download | aur-build-6c4b4394bd8ddf28d130e87e0100349f13f6e912.tar.gz aur-build-6c4b4394bd8ddf28d130e87e0100349f13f6e912.zip | |
foundation, http: export what is used above you, and nothing else
The leaf modules were the widest liars. `git` exported 19 names of which 5 were
named by nobody; `hash` exported a constant `EMPTY` that no code had ever
referenced; `time` exported a virtual clock, an `advance` and a `wrap` whose
only caller was a test that turned out not to exist. A leaf's interface is the
whole contract the rest of the crate can rely on, and these interfaces were
mostly decoration.
Nine items were genuinely dead and are gone: `hash::EMPTY`,
`git::{clone_source, count_commits, log_oneline, ls_remote_heads}`,
`recipe::is_diffable`, `pkginfo::values_of`, `time::virtual_now`, and a free
`time::advance` that had been shadowed by the `VirtualClock` method tests
actually call. Eighteen more were used only inside their own module and are now
private — `fetch`'s `Body` aside, which is the return type of a public parser
and so is part of the interface whether or not anyone writes its name.
http went 68 exported names to 27, and its last two glob re-exports
(`pub(crate) use mutations::*; use pages::*;`) are explicit lists now. That
makes the crate's glob count zero, so the allowlist in the architecture test is
empty and can stay that way.
Narrowing surfaced dead code that `pub` had been hiding, because a public item
is presumed used and never questioned: `Req::query` and `Req::body` were parsed
and stored and never read, `Res::found` had no callers, and `sse::FileBody` was
a reader nobody constructed. All four are deleted rather than re-published to
keep the warning quiet.
git 19→14, hash 8→7, recipe 11→7, urlutil 2→1, config 35→31, pkgver 18→14,
time 16→14, pkginfo 7→6, http 68→27. Crate totals: 585→516 pub, 219→115 dead,
4→0 globs.
281 passed / 0 failed, clippy -D warnings clean, release build clean,
architecture 8/8.
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 8 | ||||
| -rw-r--r-- | src/git.rs | 42 | ||||
| -rw-r--r-- | src/hash.rs | 2 | ||||
| -rw-r--r-- | src/http/auth.rs | 20 | ||||
| -rw-r--r-- | src/http/mod.rs | 13 | ||||
| -rw-r--r-- | src/http/render.rs | 48 | ||||
| -rw-r--r-- | src/http/routes/mod.rs | 17 | ||||
| -rw-r--r-- | src/http/routes/pages.rs | 8 | ||||
| -rw-r--r-- | src/http/sse.rs | 16 | ||||
| -rw-r--r-- | src/pkginfo.rs | 7 | ||||
| -rw-r--r-- | src/pkgver/mod.rs | 10 | ||||
| -rw-r--r-- | src/recipe.rs | 14 | ||||
| -rw-r--r-- | src/time.rs | 27 | ||||
| -rw-r--r-- | src/urlutil.rs | 2 |
14 files changed, 71 insertions, 163 deletions
diff --git a/src/config.rs b/src/config.rs index cd00b7f..d577cdf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -317,7 +317,7 @@ impl Config { pub fn db_path(&self) -> PathBuf { self.root.join("aur-build.db") } - pub fn mirrors_dir(&self) -> PathBuf { + fn mirrors_dir(&self) -> PathBuf { self.root.join("mirrors") } pub fn mirror_path(&self, pkgbase: &str) -> PathBuf { @@ -348,13 +348,13 @@ impl Config { pub fn store_path(&self, digest: &str) -> PathBuf { self.store_dir().join(&digest[..2.min(digest.len())]).join(digest) } - pub fn log_dir(&self) -> PathBuf { + fn log_dir(&self) -> PathBuf { self.root.join("logs") } pub fn build_log_path(&self, build_id: &str) -> PathBuf { self.log_dir().join(format!("{build_id}.log")) } - pub fn repo_dir(&self) -> PathBuf { + fn repo_dir(&self) -> PathBuf { self.root.join("repo") } pub fn repo_arch_dir(&self) -> PathBuf { @@ -409,7 +409,7 @@ fn absolute(p: &Path) -> crate::error::Result<PathBuf> { Ok(std::path::absolute(p)?) } -pub fn slug(url: &str) -> String { +fn slug(url: &str) -> String { url.chars() .map(|c| { if c.is_ascii_alphanumeric() { @@ -28,7 +28,7 @@ fn ok(out: Output, args: &[&str]) -> Result<String> { Ok(String::from_utf8_lossy(&out.stdout).to_string()) } -pub fn git_ok(cwd: Option<&Path>, args: &[&str]) -> bool { +fn git_ok(cwd: Option<&Path>, args: &[&str]) -> bool { git(cwd, args).is_ok() } @@ -47,18 +47,6 @@ pub fn ls_remote_head(url: &str) -> Result<Option<String>> { } } -pub fn ls_remote_heads(url: &str) -> Result<Vec<(String, String)>> { - let out = git(None, &["ls-remote", "--heads", url])?; - let mut v = Vec::new(); - for line in out.lines() { - let mut it = line.split_whitespace(); - if let (Some(sha), Some(name)) = (it.next(), it.next()) { - v.push((name.to_string(), sha.to_string())); - } - } - Ok(v) -} - pub fn ls_remote_ref(url: &str, refname: &str) -> Result<Option<String>> { match git(None, &["ls-remote", url, refname]) { Ok(out) => Ok(out @@ -239,40 +227,12 @@ pub fn materialize(mirror: &Path, commit: &str, dest: &Path) -> Result<()> { Ok(()) } -pub fn log_oneline(mirror: &Path, range: &str) -> Result<Vec<String>> { - let out = git(Some(mirror), &["log", "--oneline", range])?; - Ok(out.lines().map(|l| l.to_string()).collect()) -} - pub fn diff(mirror: &Path, range: &str, paths: &[&str]) -> Result<String> { let mut args: Vec<&str> = vec!["diff", "--no-color", range, "--"]; args.extend(paths); git(Some(mirror), &args) } -pub fn count_commits(mirror: &Path, range: &str) -> Result<usize> { - let out = git(Some(mirror), &["rev-list", "--count", range])?; - Ok(out.trim().parse().unwrap_or(0)) -} - -pub fn clone_source(url: &str, dest: &Path, depth: Option<usize>, branch: Option<&str>) -> Result<()> { - if let Some(parent) = dest.parent() { - std::fs::create_dir_all(parent)?; - } - let mut args: Vec<String> = vec!["clone".into(), "--quiet".into()]; - if let Some(d) = depth { - args.push(format!("--depth={d}")); - } - if let Some(b) = branch { - args.push(format!("--branch={b}")); - } - args.push(url.to_string()); - args.push(dest.display().to_string()); - let refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect(); - git(None, &refs)?; - Ok(()) -} - pub fn fetch_and_head(repo: &Path) -> Result<String> { git(Some(repo), &["fetch", "--quiet", "--no-prune", "origin"])?; head(repo) diff --git a/src/hash.rs b/src/hash.rs index f638542..5de6f3f 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -1,8 +1,6 @@ use sha2::{Digest, Sha256}; use std::io::{self, Read, Write}; -pub const EMPTY: &str = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; - pub fn hex(bytes: &[u8]) -> String { let mut h = Sha256::new(); h.update(bytes); diff --git a/src/http/auth.rs b/src/http/auth.rs index 6720607..0f174ef 100644 --- a/src/http/auth.rs +++ b/src/http/auth.rs @@ -28,7 +28,7 @@ fn counter() -> u64 { C.fetch_add(1, std::sync::atomic::Ordering::Relaxed) } -pub fn new_session() -> Option<String> { +pub(crate) fn new_session() -> Option<String> { let sid = random_hex()?; if let Ok(mut s) = sessions().lock() { s.insert(sid.clone(), false); @@ -36,11 +36,11 @@ pub fn new_session() -> Option<String> { Some(sid) } -pub fn is_valid_session(sid: &str) -> bool { +pub(crate) fn is_valid_session(sid: &str) -> bool { sessions().lock().map(|s| s.contains_key(sid)).unwrap_or(false) } -pub fn authenticate(sid: &str) { +pub(crate) fn authenticate(sid: &str) { if let Ok(mut s) = sessions().lock() { if let Some(authenticated) = s.get_mut(sid) { *authenticated = true; @@ -48,21 +48,21 @@ pub fn authenticate(sid: &str) { } } -pub fn is_authenticated(sid: &str) -> bool { +pub(crate) fn is_authenticated(sid: &str) -> bool { sessions().lock().map(|s| s.get(sid).copied().unwrap_or(false)).unwrap_or(false) } -pub fn drop_session(sid: &str) { +pub(crate) fn drop_session(sid: &str) { if let Ok(mut s) = sessions().lock() { s.remove(sid); } } -pub fn csrf_token(sid: &str) -> String { +pub(crate) fn csrf_token(sid: &str) -> String { hash::hex(format!("csrf|{sid}").as_bytes())[..32].to_string() } -pub fn csrf_ok(sid: &str, token: &str) -> bool { +pub(crate) fn csrf_ok(sid: &str, token: &str) -> bool { !token.is_empty() && is_valid_session(sid) && constant_time_eq(&csrf_token(sid), token) } @@ -78,7 +78,7 @@ fn constant_time_eq(a: &str, b: &str) -> bool { diff == 0 } -pub fn parse_cookies(header: &str) -> Vec<(String, String)> { +pub(crate) fn parse_cookies(header: &str) -> Vec<(String, String)> { header .split(';') .filter_map(|p| { @@ -89,10 +89,10 @@ pub fn parse_cookies(header: &str) -> Vec<(String, String)> { .collect() } -pub fn password_ok(cfg: &crate::config::Config, given: &str) -> bool { +pub(crate) fn password_ok(cfg: &crate::config::Config, given: &str) -> bool { cfg.password.is_empty() || constant_time_eq(&cfg.password, given) } -pub fn auth_required(cfg: &crate::config::Config) -> bool { +pub(crate) fn auth_required(cfg: &crate::config::Config) -> bool { !cfg.password.is_empty() } diff --git a/src/http/mod.rs b/src/http/mod.rs index 0d78a00..5c34466 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -9,16 +9,14 @@ use std::sync::Arc; use crate::config::Config; use crate::db::Db; -pub struct State { +pub(crate) struct State { pub cfg: Config, pub db: Db, } -pub struct Req { +pub(crate) struct Req { pub method: String, pub path: String, - pub query: String, - pub body: String, pub cookies: Vec<(String, String)>, pub query_pairs: Vec<(String, String)>, pub form_pairs: Vec<(String, String)>, @@ -40,7 +38,7 @@ impl Req { } } -pub struct Res { +pub(crate) struct Res { pub status: u16, pub content_type: String, pub body: Vec<u8>, @@ -76,9 +74,6 @@ impl Res { stream_len: None, } } - pub fn found(&self) -> bool { - self.status < 400 - } fn header(&mut self, name: &str, value: &str) { self.headers.push((name.into(), value.into())); } @@ -137,8 +132,6 @@ fn serve(state: Arc<State>, mut request: tiny_http::Request) -> std::io::Result< let req = Req { method: request.method().as_str().to_string(), path: percent_decode(&path), - query: query.clone(), - body, cookies, query_pairs: forms::parse(&query), form_pairs, diff --git a/src/http/render.rs b/src/http/render.rs index f3e4669..fdf5676 100644 --- a/src/http/render.rs +++ b/src/http/render.rs @@ -51,14 +51,14 @@ impl Page { #[derive(Template)] #[template(path = "login.html")] -pub struct Login { +pub(crate) struct Login { pub page: Page, pub error: String, } #[derive(Template)] #[template(path = "error.html")] -pub struct ErrorPage { +pub(crate) struct ErrorPage { pub page: Page, pub status: String, pub message: String, @@ -67,7 +67,7 @@ pub struct ErrorPage { #[derive(Template)] #[template(path = "dashboard.html")] -pub struct Dashboard { +pub(crate) struct Dashboard { pub page: Page, pub subscriptions: i64, pub index_count: i64, @@ -78,7 +78,7 @@ pub struct Dashboard { } #[derive(Debug, Clone)] -pub struct PublishRow { +pub(crate) struct PublishRow { pub name: String, pub version: String, pub published_at: String, @@ -88,13 +88,13 @@ pub struct PublishRow { #[derive(Template)] #[template(path = "reviews.html")] -pub struct ReviewsPage { +pub(crate) struct ReviewsPage { pub page: Page, pub rows: Vec<ReviewRow>, } #[derive(Debug, Clone)] -pub struct ReviewRow { +pub(crate) struct ReviewRow { pub id: i64, pub pkgbase: String, pub version: String, @@ -107,7 +107,7 @@ pub struct ReviewRow { #[derive(Template)] #[template(path = "review.html")] -pub struct ReviewDetail { +pub(crate) struct ReviewDetail { pub page: Page, pub c: ReviewHead, pub base_version: String, @@ -121,7 +121,7 @@ pub struct ReviewDetail { } #[derive(Debug, Clone)] -pub struct ReviewHead { +pub(crate) struct ReviewHead { pub id: i64, pub pkgbase: String, pub version: String, @@ -165,7 +165,7 @@ pub struct Subscriptions { } #[derive(Debug, Clone)] -pub struct SubRow { +pub(crate) struct SubRow { pub name: String, pub state: String, pub maintainer: String, @@ -191,7 +191,7 @@ pub struct Attention { } #[derive(Debug, Clone)] -pub struct UnbuiltRow { +pub(crate) struct UnbuiltRow { pub pkgbase: String, pub approved: String, pub serving: String, @@ -200,7 +200,7 @@ pub struct UnbuiltRow { } #[derive(Debug, Clone)] -pub struct NoticeRow { +pub(crate) struct NoticeRow { pub id: i64, pub pkgbase: String, pub kind: String, @@ -210,7 +210,7 @@ pub struct NoticeRow { } #[derive(Debug, Clone)] -pub struct StaleRow { +pub(crate) struct StaleRow { pub pkgbase: String, pub dependency: String, pub built_with: String, @@ -218,7 +218,7 @@ pub struct StaleRow { } #[derive(Debug, Clone)] -pub struct BlockedRow { +pub(crate) struct BlockedRow { pub id: String, pub id_short: String, pub pkgbase: String, @@ -235,7 +235,7 @@ pub struct Packages { } #[derive(Debug, Clone)] -pub struct IndexRow { +pub(crate) struct IndexRow { pub name: String, pub version: String, pub arch: String, @@ -245,7 +245,7 @@ pub struct IndexRow { #[derive(Template)] #[template(path = "package.html")] -pub struct PackageDetail { +pub(crate) struct PackageDetail { pub page: Page, pub name: String, pub summary: String, @@ -259,7 +259,7 @@ pub struct PackageDetail { } #[derive(Debug, Clone)] -pub struct TimelineRow { +pub(crate) struct TimelineRow { pub version: String, pub state: String, pub aur_commit: String, @@ -278,14 +278,14 @@ pub struct Builds { #[derive(Template)] #[template(path = "builds_table.html")] -pub struct BuildsTable { +pub(crate) struct BuildsTable { pub page: Page, pub rows: Vec<BuildRow>, pub recent: Vec<BuildRow>, } #[derive(Debug, Clone)] -pub struct BuildLite { +pub(crate) struct BuildLite { pub id: String, pub id_short: String, pub kind: String, @@ -309,7 +309,7 @@ pub struct BuildRow { #[derive(Template)] #[template(path = "build.html")] -pub struct BuildDetail { +pub(crate) struct BuildDetail { pub page: Page, pub id: String, pub id_short: String, @@ -326,7 +326,7 @@ pub struct BuildDetail { } #[derive(Debug, Clone)] -pub struct StepRow { +pub(crate) struct StepRow { pub step: String, pub status: String, pub attempt: i64, @@ -343,7 +343,7 @@ pub struct Audit { } #[derive(Debug, Clone)] -pub struct AuditRow { +pub(crate) struct AuditRow { pub at: String, pub actor_kind: String, pub actor: String, @@ -355,19 +355,19 @@ pub struct AuditRow { #[derive(Template)] #[template(path = "settings.html")] -pub struct Settings { +pub(crate) struct Settings { pub page: Page, pub rows: Vec<SettingRow>, pub repo: String, } #[derive(Debug, Clone)] -pub struct SettingRow { +pub(crate) struct SettingRow { pub key: String, pub value: String, } -pub fn static_asset(name: &str, accept_gzip: bool) -> crate::http::Res { +pub(crate) fn static_asset(name: &str, accept_gzip: bool) -> crate::http::Res { use crate::http::Res; match name { "app.css" => { diff --git a/src/http/routes/mod.rs b/src/http/routes/mod.rs index ed488c8..7495524 100644 --- a/src/http/routes/mod.rs +++ b/src/http/routes/mod.rs @@ -8,10 +8,17 @@ use super::{Req, Res, State}; mod mutations; mod pages; -pub(crate) use mutations::*; -pub(crate) use pages::*; - -pub fn gate(state: &State, req: &Req, sid: &str) -> Option<Res> { +pub(crate) use mutations::{ + build_cancel, build_retry, notice_ack, package_rebuild, package_withdraw, review_approve, + review_reject, reviews_bulk, sub_add, sub_pause, sub_remove, +}; +pub(crate) use pages::{ + attention, audit, build_detail, build_log, build_log_stream, builds_page, builds_with, + dashboard, metrics, package_detail, packages, panels_base, review_body, review_detail, + review_rows, reviews, settings, subscriptions, +}; + +pub(crate) fn gate(state: &State, req: &Req, sid: &str) -> Option<Res> { if !auth::auth_required(&state.cfg) { return None; } @@ -21,7 +28,7 @@ pub fn gate(state: &State, req: &Req, sid: &str) -> Option<Res> { Some(Res::redirect("/login")) } -pub fn login_form(state: &State, req: &Req) -> Res { +pub(crate) fn login_form(state: &State, req: &Req) -> Res { let page = Page::new("Sign in", csrf(state, req)); page_to_res(Login { page, error: String::new() }, 200) } diff --git a/src/http/routes/pages.rs b/src/http/routes/pages.rs index bb5db34..e8590b0 100644 --- a/src/http/routes/pages.rs +++ b/src/http/routes/pages.rs @@ -70,7 +70,7 @@ pub(crate) fn reviews(state: &State, req: &Req) -> Res { page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 200) } -pub(crate) fn full_version(c: &CandidateRow) -> String { +fn full_version(c: &CandidateRow) -> String { crate::pkgver::full_version(&c.epoch, &c.pkgver, &c.pkgrel) } @@ -368,7 +368,7 @@ pub(crate) fn package_detail(state: &State, req: &Req, name: &str) -> Res { // --------------------------------------------------------------- builds -- -pub(crate) fn build_version(db: &Db, b: &builds::BuildRow) -> String { +fn build_version(db: &Db, b: &builds::BuildRow) -> String { if let Some(cid) = b.candidate_id { if let Some(c) = candidates::candidate_by_id(db, cid).ok().flatten() { return c.version(); @@ -382,7 +382,7 @@ pub(crate) fn build_version(db: &Db, b: &builds::BuildRow) -> String { String::new() } -pub(crate) fn build_rows(state: &State) -> Vec<BuildRow> { +fn build_rows(state: &State) -> Vec<BuildRow> { builds::list( &state.db, BuildState::active(), @@ -424,7 +424,7 @@ pub(crate) fn builds_page(state: &State, req: &Req) -> Res { builds_with(state, req, page) } -pub(crate) fn recent_rows(state: &State) -> Vec<BuildRow> { +fn recent_rows(state: &State) -> Vec<BuildRow> { builds::list(&state.db, &[BuildState::Failed, BuildState::Succeeded], 10) .unwrap_or_default() .into_iter() diff --git a/src/http/sse.rs b/src/http/sse.rs index 39266be..bceba9f 100644 --- a/src/http/sse.rs +++ b/src/http/sse.rs @@ -117,19 +117,3 @@ fn read_from(path: &Path, offset: u64) -> (Vec<u8>, bool) { let grew = !buf.is_empty(); (buf, grew) } - -pub struct FileBody { - inner: std::io::Cursor<Vec<u8>>, -} - -impl FileBody { - pub fn new(bytes: Vec<u8>) -> Self { - Self { inner: std::io::Cursor::new(bytes) } - } -} - -impl Read for FileBody { - fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { - self.inner.read(buf) - } -} diff --git a/src/pkginfo.rs b/src/pkginfo.rs index 37646d0..2cf449e 100644 --- a/src/pkginfo.rs +++ b/src/pkginfo.rs @@ -112,10 +112,3 @@ fn push_entry(out: &mut Vec<Installed>, line: &str) { fn fields(text: &str) -> impl Iterator<Item = (&str, &str)> { text.lines().filter_map(|l| l.split_once('=')).map(|(k, v)| (k.trim(), v.trim())) } - -pub fn values_of(text: &str, key: &str) -> Vec<String> { - fields(text) - .filter(|(k, _)| *k == key) - .map(|(_, v)| v.to_string()) - .collect() -} diff --git a/src/pkgver/mod.rs b/src/pkgver/mod.rs index 450d70f..ef00b55 100644 --- a/src/pkgver/mod.rs +++ b/src/pkgver/mod.rs @@ -39,10 +39,10 @@ impl Version { let (epoch, pkgver, pkgrel) = split_full_version(v); Self { epoch, pkgver, pkgrel } } - pub fn cmp_full(&self, other: &Version) -> Ordering { + fn cmp_full(&self, other: &Version) -> Ordering { compare(self.epoch_as_i64(), &self.pkgver, &self.pkgrel, other.epoch_as_i64(), &other.pkgver, &other.pkgrel) } - pub fn epoch_as_i64(&self) -> i64 { + fn epoch_as_i64(&self) -> i64 { self.epoch.trim().parse().unwrap_or(0) } pub fn display(&self) -> String { @@ -187,10 +187,6 @@ pub fn is_downgrade(current: &str, new: &str) -> bool { vercmp(current, new) == Ordering::Greater } -pub fn same_version(current: &str, new: &str) -> bool { - vercmp(current, new) == Ordering::Equal -} - // ------------------------------------------------------------- dep strings -- #[derive(Debug, Clone, PartialEq, Eq)] @@ -280,7 +276,7 @@ impl fmt::Display for Dep { } } -pub fn parse_deps(list: &[String]) -> Vec<Dep> { +fn parse_deps(list: &[String]) -> Vec<Dep> { list.iter().filter_map(|s| Dep::parse(s)).collect() } diff --git a/src/recipe.rs b/src/recipe.rs index 3599ded..5e8f9a3 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use crate::db::model::{Recipe, SourceEntry}; use crate::error::{Error, Result}; -pub fn parse_srcinfo(text: &str) -> Result<Recipe> { +fn parse_srcinfo(text: &str) -> Result<Recipe> { let mut r = Recipe::default(); let mut current: Option<String> = None; let mut base_seen = false; @@ -236,7 +236,7 @@ fn split_array_elements(s: &str) -> Vec<String> { out.into_iter().filter(|e| !e.is_empty()).collect() } -pub fn parse_source_entries(list: &[String]) -> Result<Vec<SourceEntry>> { +fn parse_source_entries(list: &[String]) -> Result<Vec<SourceEntry>> { let mut out = Vec::new(); for (index, raw) in list.iter().enumerate() { let s = raw.trim(); @@ -316,15 +316,7 @@ pub fn recipe_from_tree(files: &BTreeMap<String, String>) -> Result<Recipe> { Ok(r) } -pub fn is_diffable(path: &str) -> bool { - let ext = path.rsplit('.').next().unwrap_or(""); - !matches!( - ext, - "png" | "jpg" | "gif" | "ico" | "pdf" | "gz" | "zst" | "xz" | "bz2" | "zip" | "deb" | "rpm" - ) -} - -pub fn pkgbuild_bodies(text: &str) -> String { +fn pkgbuild_bodies(text: &str) -> String { let mut out = String::new(); let mut inside = false; for line in text.lines() { diff --git a/src/time.rs b/src/time.rs index 7587721..29206d6 100644 --- a/src/time.rs +++ b/src/time.rs @@ -110,21 +110,14 @@ where clock::wrap(f) } +/// The handle tests hold to keep the clock frozen; dropping it releases the +/// clock, which is why `virtualize` hands one back rather than setting a global. #[cfg(feature = "test-support")] -pub fn virtualize() -> clock::VirtualClock { - clock::virtualize() -} - -#[cfg(feature = "test-support")] -pub fn virtual_now() -> Option<DateTime<Utc>> { - clock::now() -} +pub use clock::VirtualClock; -/// Move the frozen clock along, so a control loop can be made to believe a tick, -/// a lease or a cooldown has elapsed without anything waiting for it. #[cfg(feature = "test-support")] -pub fn advance(d: Duration) { - clock::advance(d) +pub fn virtualize() -> clock::VirtualClock { + clock::virtualize() } #[cfg(feature = "test-support")] @@ -181,15 +174,7 @@ mod clock { true } - pub fn advance(d: Duration) { - let mut at = lock(&AT); - if let Some(t) = *at { - let step = chrono::TimeDelta::from_std(d).unwrap_or_else(|_| chrono::TimeDelta::zero()); - *at = Some(t + step); - } - } - - pub fn wrap<F, T>(f: F) -> impl FnOnce() -> T + pub(super) fn wrap<F, T>(f: F) -> impl FnOnce() -> T where F: FnOnce() -> T + Send + 'static, T: Send + 'static, diff --git a/src/urlutil.rs b/src/urlutil.rs index 0452ccd..12f74e5 100644 --- a/src/urlutil.rs +++ b/src/urlutil.rs @@ -1,6 +1,6 @@ use std::collections::BTreeSet; -pub fn host_of(source: &str) -> Option<String> { +fn host_of(source: &str) -> Option<String> { let s = source.rsplit("::").next().unwrap_or(source); let s = s.rsplit('+').next().unwrap_or(s); let rest = s.split("://").nth(1)?; |
