diff options
Diffstat (limited to 'src/pipeline/steps.rs')
| -rw-r--r-- | src/pipeline/steps.rs | 70 |
1 files changed, 19 insertions, 51 deletions
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<StepResult> { 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<Recipe> { crate::recipe::recipe_from_tree(&files) } -fn parse_pkginfo(text: &str) -> std::collections::HashMap<String, String> { - 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<String> { - 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 -} |
