Skip to content

Commit 0ef4d2a

Browse files
committed
pacman-helper.sh quick_*: be more careful about removing archives
An important part of the `quick_*` functions is to remove the archives that are no longer needed. For example, when adding a new version with `quick_add`, the package archive of the superseded version (if any) is removed. Example: When deploying OpenSSH v9.9p2, `pacman-helper.sh quick_add `openssh-9.9p2-1-x86_64.pkg.tar.xz`, was called, which removed `openssh-9.9p1-2-x86_64.pkg.tar.xz` because that was no longer needed, and likewise the corresponding `.sig` file. As pointed out by Jeremy Drake, the shell pattern that is used to perform this job, however, is too fragile: it does not account for package names that have an `-<digit>` infix, e.g. `msys2-runtime-3.3`. That is, when upgrading `msys2-runtime` via `quick_add`, it would not only remove the superseded `msys2-runtime` package, but also the `msys2-runtime-3.3` and the `msys2-runtime-3.3-devel` archives as well! Lets' be more careful about this. Sadly, there is no way to do this with non-greedy patterns: wildcard patterns only support greedy matches. That is, `-[0-9]*` will happily match anything via that `*`, including `-<digit>`, i.e. the maximal suffix, not the minimal suffix. So let's use "exclude patterns" (a Git-specific feature) to exclude any false positives. This is still slightly fragile, as it will prevent `quick_*` from working correctly when passing, say, _both_ `msys2-runtime-3.3` _and_ `msys2-runtime`: exclude patterns are not positional, and therefore this command would _not_ match `msys2-runtime-3.3`: git ls-files -- \ 'msys2-runtime-[0-9]*' \ ':(exclude)msys2-runtime-[0-9]*-*-*-*' \ 'msys2-runtime-3.3-[0-9]*' \ ':(exclude)msys2-runtime-3.3-[0-9]*-*-*-*' The first `:(exclude)` pattern would prevent the subsequent pattern from matching `msys2-runtime-3.3-<digit>`. Nevertheless, this scenario is unlikely, as the principal use case of `quick_add` is the `/deploy` slash command in Git for Windows' MINGW-packages and MSYS2-packages PullRequests. And there, we only deploy a single package at a time, not two. And even in case we should run afoul of this fragility in a (semi-manual) `quick_remove` invocation, the fix is easy: manually remove the files that haven't been removed by mistake. This is all about the tip of the `x86_64`, `aarch64` and `i686` branches of https://github.com/git-for-windows/pacman-repo, after all, and such a manual fix is but a trivial PullRequest away. Contrary to the problem addressed by this commit, this fragility would not affect the operation of the Pacman repository, either, because it would serve too many files, not too few. Helped-by: Jeremy Drake <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 3df2696 commit 0ef4d2a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pacman-helper.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,18 @@ quick_action () { # <action> <file>...
431431
printf '%s\n' $msys $mingw |
432432
sed '/\.pkg\.tar/{
433433
s/-[^-]*-[^-]*-[^-]*\.pkg\.tar\.\(xz\|zst\)$/-[0-9]*/
434-
b
434+
b1
435435
}
436-
s/$/-[0-9]*/' |
436+
s/$/-[0-9]*/
437+
:1
438+
p
439+
# Prevent false positives (e.g. deleting `msys2-runtime-3.3` when
440+
# updating `msys2-runtime`) by requiring the suffix to be of the form
441+
# `-<pkgver>-<pkgrel>-<arch><pkgext>`. Sadly, there are no non-greedy
442+
# wildcards, therefore do this via an "exclude pattern" instead:
443+
# `:(exclude)<pkgname>-[0-9]*-*-*-*`
444+
s/$/-*-*-*/
445+
s/^/:(exclude)/' |
437446
xargs git rm --sparse --cached -- ||
438447
die "Could not remove the existing versions from the Git branch in $arch"
439448

0 commit comments

Comments
 (0)