abuild: fix cleanoldpkg

we should only delete packages of the specified architecture

fixes https://gitlab.alpinelinux.org/alpine/abuild/-/issues/10078
This commit is contained in:
Natanael Copa 2022-12-06 16:59:03 +01:00
parent ee13f777d5
commit e8c1ce6127
2 changed files with 58 additions and 2 deletions

View File

@ -615,7 +615,7 @@ cleanoldpkg() {
msg "Cleaning all packages except $pkgver-r$pkgrel..."
for i in $allpackages; do
subpkg_set "$i"
for j in "$REPODEST"/$repo/*/$subpkgname-[0-9]*.apk ; do
for j in "$REPODEST"/$repo/$CARCH/$subpkgname-[0-9]*.apk ; do
[ "${j##*/}" = "$subpkgname-$pkgver-r$pkgrel.apk" ] \
&& continue
rm -f "$j"

View File

@ -28,10 +28,12 @@ init_tests \
abuild_amove \
abuild_doc \
abuild_dev \
abuild_check_maintainer
abuild_check_maintainer \
abuild_cleanoldpkg
export ABUILD_SHAREDIR=$(atf_get_srcdir)/..
export ABUILD_CONF=/dev/null
export ABUILD_APK_INDEX_OPTS="--allow-untrusted"
export GIT_CONFIG_GLOBAL="$(atf_get_srcdir)/testdata/gitconfig"
export REPODEST="$PWD"/packages
@ -695,3 +697,57 @@ abuild_check_maintainer_body() {
atf_check abuild check_maintainer
done
}
abuild_cleanoldpkg_body() {
init_keys
mkdir -p main/foo
cd main/foo
for arch in aarch64 x86_64; do
for v in 0.9 1.0 1.1; do
cat > APKBUILD <<-EOF
# Maintainer: Test User 123 <123@example.com>
# test package
pkgname="foo"
pkgver="$v"
pkgrel=0
pkgdesc='Dummy test package - dev'
url='https://gitlab.alpinelinux.org/alpine/aports'
arch='noarch'
license='MIT'
options='!check'
package() {
mkdir -p "\$pkgdir"
}
EOF
CARCH=$arch atf_check -e not-empty abuild
done
done
CARCH=aarch64 atf_check -e match:"Cleaning" abuild cleanoldpkg
find "$REPODEST"
# should keep the current APKBUILD version
for arch in aarch64 x86_64; do
f="$REPODEST"/main/$arch/foo-1.1-r0.apk
if ! test -e "$f"; then
atf_fail "$f was deleted"
fi
done
# should remove old packages of aarch64
for i in 0.9 1.0; do
f="$REPODEST"/main/aarch64/foo-$i-r0.apk
if test -e "$f"; then
atf_fail "$f was not deleted"
fi
done
# should not delete other arches than aarch64
for i in 0.9 1.0; do
f="$REPODEST"/main/x86_64/foo-$i-r0.apk
if ! test -e "$f"; then
atf_fail "$f was deleted"
fi
done
}