From d9c8402180749df4452dc37febace4d933b8407d Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 09:12:28 +0000 Subject: =?UTF-8?q?pkginfo:=20.PKGINFO/.BUILDINFO=20parsing=20gets=20a=20r?= =?UTF-8?q?eal=20home,=20and=20a=20parser=20bug=20fix=20(=C2=A710.1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ingest decides what the index claims about a package and what the world snapshot records by reading two text files out of a tar inside a zstd stream. That code was living in src/shims — the test harness — which meant production depended on the harness for its view of a package's own metadata. Moved to src/pkginfo.rs, with the shim now delegating to it so the harness and the production path cannot disagree about what a package says about itself. Still no libalpm: tar + zstd + eighty lines of key = value parsing. Unknown keys are ignored rather than rejected, because makepkg adds fields over time and a new one must not stop us publishing. **The parser had a real bug.** A .BUILDINFO installed block puts its first entry on the same line as the key: installed = glibc 2.39-1 x86_64 - gmp 6.3.0-1 x86_64 - The old code skipped the header line, so the first dependency was silently dropped from every snapshot — exactly the kind of gap that makes staleness quietly wrong. The header line is parsed now. tests/world.rs builds real .pkg.tar.zst files and asserts the fields come out of the archive: repeated keys stay lists, an archive with no .PKGINFO is refused rather than defaulted from the filename, and the world snapshot contains our own packages and none of glibc/pacman/binutils. The empty-snapshot case for a first build is asserted too — nothing of ours existed yet, and recording that honestly beats inventing a world. Split pkgbases produce one approval, one release and N index rows each with its own artifact, asserted directly here. 143 tests pass, clippy clean. --- src/pipeline/steps.rs | 70 ++++++++++++++------------------------------------- 1 file changed, 19 insertions(+), 51 deletions(-) (limited to 'src/pipeline') diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs index b925afb..3f575bd 100644 --- a/src/pipeline/steps.rs +++ b/src/pipeline/steps.rs @@ -264,24 +264,32 @@ fn collect(ctx: &Ctx) -> Result { for path in entries { let bytes = std::fs::read(&path)?; let (digest, size) = crate::hash::digest_file(&path)?; - let pkginfo = crate::shims::read_pkginfo(&bytes) + // Read what the package says about itself out of the archive, rather + // than trusting what the build claimed on stdout (§10.1). + let pkginfo = crate::pkginfo::pkginfo_text(&bytes) .map_err(|e| Error::invalid(format!("{}: {e}", path.display())))?; - let buildinfo = crate::shims::read_buildinfo(&bytes).unwrap_or_default(); - let meta = parse_pkginfo(&pkginfo); + let meta = crate::pkginfo::parse_pkginfo(&pkginfo); + // `.BUILDINFO` is what the world snapshot is built from. Absent is not + // fatal — the snapshot is then simply empty for this package — but a + // present-but-unparseable one would be a lie we should not swallow. + let buildinfo = crate::pkginfo::buildinfo_text(&bytes).unwrap_or_default(); let sig = path.with_extension("pkg.tar.zst.sig"); pkgs.push(CollectedPkg { - name: meta.get("pkgname").cloned().unwrap_or_default(), - version: meta.get("pkgver").cloned().unwrap_or_default(), - arch: meta.get("pkgarch").cloned().unwrap_or_else(|| ctx.cfg.arch.clone()), + name: meta.name.clone(), + version: meta.version.clone(), + arch: if meta.arch.is_empty() { ctx.cfg.arch.clone() } else { meta.arch.clone() }, path: path.display().to_string(), digest, size, signature_path: sig.exists().then(|| sig.display().to_string()), - depends: meta_multi(&pkginfo, "depend"), - makedepends: meta_multi(&pkginfo, "makedepend"), - provides: meta_multi(&pkginfo, "provides"), - conflicts: meta_multi(&pkginfo, "conflict"), - installed: parse_installed(&buildinfo), + depends: meta.depends.clone(), + makedepends: meta.makedepends.clone(), + provides: meta.provides.clone(), + conflicts: meta.conflicts.clone(), + installed: crate::pkginfo::parse_installed(&buildinfo) + .into_iter() + .map(|i| (i.name, i.version)) + .collect(), }); } if pkgs.is_empty() { @@ -414,43 +422,3 @@ pub fn recipe_at(dir: &Path) -> Result { crate::recipe::recipe_from_tree(&files) } -fn parse_pkginfo(text: &str) -> std::collections::HashMap { - let mut m = std::collections::HashMap::new(); - for line in text.lines() { - if let Some((k, v)) = line.split_once('=') { - m.insert(k.trim().to_string(), v.trim().to_string()); - } - } - m -} - -fn meta_multi(text: &str, key: &str) -> Vec { - text.lines() - .filter_map(|l| l.split_once('=')) - .filter(|(k, _)| k.trim() == key) - .map(|(_, v)| v.trim().to_string()) - .collect() -} - -/// `.BUILDINFO` `installed =` block: ` name version arch sig` per line. -fn parse_installed(text: &str) -> Vec<(String, String)> { - let mut out = Vec::new(); - let mut in_block = false; - for line in text.lines() { - if line.trim_start().starts_with("installed") { - in_block = true; - continue; - } - if in_block { - if !line.starts_with(' ') && !line.starts_with('\t') { - in_block = false; - continue; - } - let mut it = line.split_whitespace(); - if let (Some(name), Some(version)) = (it.next(), it.next()) { - out.push((name.to_string(), version.to_string())); - } - } - } - out -} -- cgit v1.2.3