diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/http/mod.rs | 14 | ||||
| -rw-r--r-- | src/pipeline/mod.rs | 24 |
2 files changed, 31 insertions, 7 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs index 24da43f..81c526c 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -36,17 +36,22 @@ pub struct Req { pub body: String, pub cookies: Vec<(String, String)>, pub query_pairs: Vec<(String, String)>, + /// The body's form pairs, parsed once when the request is decoded (n-3). + /// `form_get` used to re-parse the whole body on every call, and a single + /// handler — approve, with its two hashes, its note and its CSRF token — + /// asks five times. + pub form_pairs: Vec<(String, String)>, /// Whether the client said it can take gzip. Used to decide whether to hand /// out the precompressed static asset. pub accept_gzip: bool, } impl Req { - pub fn form(&self) -> Vec<(String, String)> { - forms::parse(&self.body) + pub fn form(&self) -> &[(String, String)] { + &self.form_pairs } pub fn form_get(&self, key: &str) -> Option<String> { - self.form().into_iter().find(|(k, _)| k == key).map(|(_, v)| v) + self.form_pairs.iter().find(|(k, _)| k == key).map(|(_, v)| v.clone()) } pub fn query_get(&self, key: &str) -> Option<String> { self.query_pairs.iter().find(|(k, _)| k == key).map(|(_, v)| v.clone()) @@ -162,6 +167,8 @@ fn serve(state: Arc<State>, mut request: tiny_http::Request) -> std::io::Result< .find(|h| h.field.equiv("Accept-Encoding")) .map(|h| h.value.as_str().contains("gzip")) .unwrap_or(false); + // Parsed once, here, rather than per `form_get` call (n-3). + let form_pairs = forms::parse(&body); let req = Req { method: request.method().as_str().to_string(), path: percent_decode(&path), @@ -169,6 +176,7 @@ fn serve(state: Arc<State>, mut request: tiny_http::Request) -> std::io::Result< body, cookies, query_pairs: forms::parse(&query), + form_pairs, accept_gzip, }; diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index c3a2cb3..20648c0 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -283,10 +283,26 @@ pub fn enqueue_manual_rebuild(cfg: &Config, db: &Db, pkgbase: &str) -> Result<St .ok_or_else(|| Error::not_found(format!("pkgbase {pkgbase}")))?; let rel = db::accepted_release(db, pkgbase)? .ok_or_else(|| Error::invalid(format!("{pkgbase} has no accepted release")))?; - let identity = crate::hash::hex_str(&format!( - "{}|{}|manual", - rel.aur_commit, rel.recipe_hash - )); + // A manual rebuild is the accepted release asked for again, so its identity + // is derived from what that release actually is — commit, recipe, pins, + // digests — through the same canonical-JSON hash every other identity uses + // (n-5). The old version was an ad-hoc `commit|hash|manual` string: a + // different format for the same concept, with a delimiter that could appear + // inside the values, and no pins or digests at all, so two releases with the + // same recipe but different upstream commits... were distinguished only by + // luck. `requested` is what keeps a rebuild a *distinct* build from the one + // that produced the release, while staying deterministic (§8.2): clicking + // rebuild twice is one build, not two. + let identity = format!( + "sha256:{}", + crate::hash::hex(crate::hash::canonical_json(&serde_json::json!({ + "aur_commit": rel.aur_commit, + "recipe_hash": rel.recipe_hash, + "upstream_pins": rel.pins(), + "source_digests": rel.digests(), + "requested": "manual_rebuild", + }))?.as_bytes()) + ); let world = publish::index_world(db)?; let world_hash = crate::hash::canonical_json(&world)?; let id = builds::build_id(pkgbase, &identity, &world_hash, &cfg.build_profile); |
