diff options
| author | aur-build <aur-build@localhost> | 2026-11-19 14:15:16 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-19 14:15:16 +0000 |
| commit | 153e72cc797c1e45a60f4896d00163fb4bdf3056 (patch) | |
| tree | 7e2308552e5f5a33f4ddad07eba7a816e28e8568 /src/shims/mod.rs | |
| parent | 43a2bfaaac60bc378135ad90c46c9d42777aeb1e (diff) | |
| download | aur-build-153e72cc797c1e45a60f4896d00163fb4bdf3056.tar.gz aur-build-153e72cc797c1e45a60f4896d00163fb4bdf3056.zip | |
publish: repo-add decides the database filename
Publishing renders the index before the DB commits and renames it into place
after, so a crash between the two leaves the old index serving (I4). The way
that was written did it at `<db>.tar.gz.tmp` beside the live file — a filename
real repo-add refuses, because its database argument has to be a name pacman
would accept. Every publish test passed; the first real package anyone tried to
publish died at the last step with the release already committed.
`render_db` now renders into a scratch directory under the served directory,
under the name a consumer will download. Same filesystem, so the rename is still
the atomic swap, and the live database is never the file repo-add is writing
into. `publish`, `reconcile` and `withdraw_package` all had the bug and all share
the helper now; `reconcile` sweeps scratch directories a crash left behind.
`run_repo_add` drops `-s` too: repo-add would sign into scratch space that is
about to be deleted, and `publish::sign` already signs the renamed file.
The reason 238 tests missed this is that the shim would write the database
anywhere it was told. It now enforces the accepted set — measured against
`repo-add (pacman) 7.1.0`, not read out of its docs — with the real tool's
wording and exit status, and a gated test re-derives the set against the
installed tool, in the shape of the vercmp oracle. A shim that is more
permissive than its tool is not a test of the tool.
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()))?; |
