diff options
| author | dev <dev@localhost> | 2026-11-20 17:55:31 +0000 |
|---|---|---|
| committer | dev <dev@localhost> | 2026-11-20 17:55:31 +0000 |
| commit | 466f6f7e223f56670feabb0737cf97f708aa45f2 (patch) | |
| tree | 080176012bcd830af207405823a7535c79d0510e /src/watch/sources.rs | |
| parent | 1cd680c12dc191bfbf7afa8ad8308524776e60ae (diff) | |
| download | aur-build-466f6f7e223f56670feabb0737cf97f708aa45f2.tar.gz aur-build-466f6f7e223f56670feabb0737cf97f708aa45f2.zip | |
watch: one source interface, and the fail-closed check lives with the source
The step machine reached into two of watch's internals and reassembled the
rules itself: `mirror::read_tree` then `Tree::recipe_hash` to re-derive the
hash a reviewer approved, and `digests::cached_path` then
`digests::download_and_cache` then its own comparison to check a payload.
The comparison is the part that must never be skipped, and it was sitting in
whichever step happened to want a file — a step could have forgotten it and
nothing would have noticed.
`watch::sources` is the interface now: what a tree hashes to, and a guarantee
that a cached source is the bytes its name claims. `verify_cached` owns the
fail-closed test and its message verbatim. `download_and_cache` and
`cached_path` are `pub(crate)` again, so the cache layout is watch's business
again; `watch/mod.rs` no longer re-exports them.
`src/pipeline` now names exactly one watch path.
Detection is untouched by construction — no git-invoking function changed —
and the census agrees: 264 successful git execs on the detect binary before
and after. (An initial reading of 1320 vs 264 was PATH-probe ENOENTs from a
differing shell PATH, not git work; counted with suite-cost.py's own rule of
successful execve only, the two runs are identical.)
watch.pub 31->30. `read_tree` moved into the test-only column: the pipeline
stopped naming it, and what remains are watch's own calls plus the two tests
that exercise its one-batch-read contract directly.
277 passed / 0 failed, clippy -D warnings clean.
Diffstat (limited to 'src/watch/sources.rs')
| -rw-r--r-- | src/watch/sources.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/watch/sources.rs b/src/watch/sources.rs new file mode 100644 index 0000000..7b56774 --- /dev/null +++ b/src/watch/sources.rs @@ -0,0 +1,44 @@ +//! The source interface the build pipeline asks watch for. +//! +//! The step machine used to reach into two of watch's internals and reassemble +//! the rules itself: `mirror::read_tree` plus `Tree::recipe_hash` to re-derive +//! the hash a reviewer approved, and `digests::cached_path` plus +//! `digests::download_and_cache` plus its own comparison to check a payload. +//! That put the fail-closed test — the one thing that must never be skipped — +//! in whichever step happened to want a file, and left the pipeline knowing how +//! watch caches. +//! +//! Two calls cover what it actually needs: what a tree hashes to, and a +//! guarantee that a cached source is the bytes its name claims. + +use std::path::Path; + +use crate::config::Config; +use crate::db::Db; +use crate::error::{Error, Result}; +use crate::watch::digests::{cached_path, download_and_cache}; +use crate::watch::mirror::read_tree; + +/// The recipe hash of a mirror at a commit — the same value the reviewer saw, +/// so a build can refuse a tree that moved underneath the approval. +pub fn recipe_hash(mirror: &Path, commit: &str) -> Result<String> { + Ok(read_tree(mirror, commit)?.recipe_hash()) +} + +/// Ensure `url` is cached and that what is cached hashes to `digest`. +/// +/// Fails closed on a mismatch rather than handing back bytes that are not what +/// was approved: a source that quietly changed is exactly the case the whole +/// approval chain exists to catch. +pub fn verify_cached(cfg: &Config, db: &Db, url: &str, digest: &str) -> Result<()> { + let found = match cached_path(db, url, digest) { + Some(p) => crate::hash::digest_file(&p)?.0, + None => download_and_cache(cfg, db, url)?.0, + }; + if found != digest { + return Err(Error::fail_closed(format!( + "source {url} hashed to {found} but the candidate recorded {digest}" + ))); + } + Ok(()) +} |
