summaryrefslogtreecommitdiffstats
path: root/src/shims/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/shims/mod.rs')
-rw-r--r--src/shims/mod.rs103
1 files changed, 31 insertions, 72 deletions
diff --git a/src/shims/mod.rs b/src/shims/mod.rs
index 5cf9ac7..a34cf7d 100644
--- a/src/shims/mod.rs
+++ b/src/shims/mod.rs
@@ -520,8 +520,8 @@ pub fn repo_add(args: &[String], _m: &Manifest) -> Result<i32, String> {
let mut ar = tar::Builder::new(Vec::new());
for pkg in &pkgs {
let bytes = std::fs::read(pkg).map_err(|e| format!("repo-add: {}: {e}", pkg.display()))?;
- let pkginfo = read_pkginfo(&bytes)?;
- let (name, version, arch, extra) = parse_pkginfo(&pkginfo);
+ let pkginfo = crate::pkginfo::pkginfo_text(&bytes)?;
+ let (name, version, arch, extra) = pkginfo_fields(&bytes)?;
let mut entry = String::new();
entry.push_str(&format!("%FILENAME%\n{}\n\n", pkg.file_name().unwrap().to_string_lossy()));
entry.push_str(&format!("%NAME%\n{name}\n\n"));
@@ -561,77 +561,36 @@ pub fn repo_add(args: &[String], _m: &Manifest) -> Result<i32, String> {
Ok(0)
}
-/// Pull `.PKGINFO` out of a `.pkg.tar.zst`. The real parsing lives in
-/// `crate::pkginfo`, which the pipeline also uses — the shim and the production
-/// path must agree about what a package says about itself, or a test that passes
-/// here would not mean anything.
-pub fn read_pkginfo(pkg_bytes: &[u8]) -> Result<String, String> {
- crate::pkginfo::pkginfo_text(pkg_bytes)
-}
-
-pub fn read_buildinfo(pkg_bytes: &[u8]) -> Result<String, String> {
- crate::pkginfo::buildinfo_text(pkg_bytes)
-}
-
-fn parse_pkginfo(s: &str) -> (String, String, String, String) {
- let mut name = String::new();
- let mut version = String::new();
- let mut arch = String::new();
- let mut groups = Vec::new();
- let mut deps = Vec::new();
- let mut optdeps = Vec::new();
- let mut provides = Vec::new();
- let mut conflicts = Vec::new();
- let mut replaces = Vec::new();
- let mut license = Vec::new();
- let mut desc = String::new();
- let mut url = String::new();
- for line in s.lines() {
- let (k, v) = match line.split_once('=') {
- Some((k, v)) => (k.trim(), v.trim()),
- None => continue,
- };
- match k {
- "pkgname" => name = v.to_string(),
- "pkgver" => version = v.to_string(),
- "pkgarch" => arch = v.to_string(),
- "pkgdesc" => desc = v.to_string(),
- "url" => url = v.to_string(),
- "license" => license.push(v.to_string()),
- "depend" => deps.push(v.to_string()),
- "optdepend" => optdeps.push(v.to_string()),
- "checkdepend" => {}
- "makedepend" => {}
- "provides" => provides.push(v.to_string()),
- "conflict" => conflicts.push(v.to_string()),
- "replace" => replaces.push(v.to_string()),
- "group" => groups.push(v.to_string()),
- _ => {}
- }
- }
+/// Pull `.PKGINFO` out of a `.pkg.tar.zst` and render the `DESC` fields a
+/// pacman database carries beyond the fixed ones.
+///
+/// Both halves come from `crate::pkginfo`, the parser the production pipeline
+/// uses (§6 M-4). The shim used to carry its own copy of the field parser, and
+/// two parsers that can drift is a supply-chain-shaped foot-gun in a system
+/// whose whole job is provenance: a test that passed because the shim read a
+/// package one way would not have meant the pipeline read it that way.
+fn pkginfo_fields(pkg_bytes: &[u8]) -> Result<(String, String, String, String), String> {
+ let text = crate::pkginfo::pkginfo_text(pkg_bytes)?;
+ let info = crate::pkginfo::parse_pkginfo(&text);
let mut extra = String::new();
- let mut push = |tag: &str, vals: &Vec<String>| {
- if !vals.is_empty() {
- extra.push_str(&format!("{tag}\n{}\n\n", vals.join("\n")));
- }
- };
- push("%DESC%", &desc_vec(&desc));
- push("%URL%", &url_vec(&url));
- push("%LICENSE%", &license);
- push("%DEPENDS%", &deps);
- push("%OPTDEPENDS%", &optdeps);
- push("%PROVIDES%", &provides);
- push("%CONFLICTS%", &conflicts);
- push("%REPLACES%", &replaces);
- push("%GROUPS%", &groups);
- (name, version, arch, extra)
-}
-
-fn desc_vec(s: &str) -> Vec<String> {
- if s.is_empty() { vec![] } else { vec![s.to_string()] }
-}
-fn url_vec(s: &str) -> Vec<String> {
- if s.is_empty() { vec![] } else { vec![s.to_string()] }
+ {
+ let mut push = |tag: &str, vals: &[String]| {
+ if !vals.is_empty() {
+ extra.push_str(&format!("{tag}\n{}\n\n", vals.join("\n")));
+ }
+ };
+ let one = |s: &str| -> Vec<String> { if s.is_empty() { vec![] } else { vec![s.to_string()] } };
+ push("%DESC%", &one(&info.desc));
+ push("%URL%", &one(&info.url));
+ push("%LICENSE%", &info.license);
+ push("%DEPENDS%", &info.depends);
+ push("%OPTDEPENDS%", &info.optdepends);
+ push("%PROVIDES%", &info.provides);
+ push("%CONFLICTS%", &info.conflicts);
+ push("%REPLACES%", &info.replaces);
+ push("%GROUPS%", &info.groups);
+ }
+ Ok((info.name, info.version, info.arch, extra))
}
/// `gpg --detach-sign --output <sig> <file>`: write a deterministic stand-in