diff options
Diffstat (limited to 'src/shims/mod.rs')
| -rw-r--r-- | src/shims/mod.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/shims/mod.rs b/src/shims/mod.rs index d0c253d..7118283 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -562,6 +562,38 @@ fn installed_db() -> Option<std::path::PathBuf> { /// The real tool appends; `-R` replaces an existing entry. We rebuild the whole /// db from the packages given, which is what our publish step does anyway (it /// passes exactly the packages that belong in the index). +/// The database filenames pacman's repo-add accepts — and therefore the ones +/// this shim must accept, and no others. +/// +/// A shim that is more permissive than the tool it stands in for is worse than no +/// shim: the pipeline used to render its database to `<db>.tar.gz.tmp` and rename +/// it into place, real repo-add rejects that filename as a usage error, and every +/// publish test in the suite passed because the shim would write anywhere. That +/// is how the first real package anyone tried to publish died at the last step. +/// This list is the accepted set as measured against `repo-add (pacman) 7.1.0`: +/// the `.db.tar` forms with or without a compression suffix, and nothing else — +/// not `aur.db`, not `aur.db.gz`, and not the `.files.*` forms, which belong to +/// `repo-files`. +pub const DB_SUFFIXES: [&str; 5] = [ + ".db.tar", + ".db.tar.gz", + ".db.tar.zst", + ".db.tar.bz2", + ".db.tar.xz", +]; + +/// Whether repo-add would accept this path as its database argument. +pub fn valid_db_arg(p: &Path) -> bool { + let name = p + .file_name() + .map(|s| s.to_string_lossy().into_owned()) + .unwrap_or_default(); + !name.is_empty() + && DB_SUFFIXES + .iter() + .any(|sfx| name.ends_with(sfx)) +} + pub fn repo_add(args: &[String], _m: &Manifest) -> Result<i32, String> { // `-p <key>` and friends take a value; a naive filter would treat the key id // as a package path. @@ -584,6 +616,15 @@ pub fn repo_add(args: &[String], _m: &Manifest) -> Result<i32, String> { Some((db, rest)) => (PathBuf::from(db), rest.iter().map(|p| PathBuf::from(p.as_str())).collect::<Vec<_>>()), None => return Err("repo-add: no database given".into()), }; + if !valid_db_arg(&db_path) { + // Same wording and same exit status as the real tool, so a caller that + // learns to branch on one learns to branch on the other. + eprintln!( + "==> ERROR: '{}' does not have a valid database archive extension.", + db_path.display() + ); + return Ok(1); + } 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()))?; |
