From 40f6f12249ee5c588ddff0b706ddb9916c4e84de Mon Sep 17 00:00:00 2001 From: yumeyao Date: Fri, 11 Mar 2022 17:41:33 +0800 Subject: [PATCH 1/2] Supersedes packages of same source package for negative limit. --- distribution.c | 2 +- target.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/distribution.c b/distribution.c index 11e2fe04..3730d3f0 100644 --- a/distribution.c +++ b/distribution.c @@ -444,7 +444,7 @@ CFallSETPROC(distribution, label) CFallSETPROC(distribution, description) CFallSETPROC(distribution, signed_by) CFsignwithSETPROC(distribution, signwith) -CFnumberSETPROC(distribution, -1, LLONG_MAX, limit) +CFnumberSETPROC(distribution, LLONG_MIN, LLONG_MAX, limit) CFfileSETPROC(distribution, deb_override) CFfileSETPROC(distribution, udeb_override) CFfileSETPROC(distribution, dsc_override) diff --git a/target.c b/target.c index 0984fc46..61f13e3b 100644 --- a/target.c +++ b/target.c @@ -668,6 +668,46 @@ retvalue target_addpackage(struct target *target, struct logger *logger, const c if (trackingdata == NULL) target->staletracking = true; } + + while (RET_IS_OK(r) && target->distribution->limit < 0) { + // Remove older versions under the same source package name for negative limit + long long limit, num; + char *source; + char *sourceversion; + + r = target->getsourceandversion(control, name, &source, &sourceversion); + if (r == RET_NOTHING || RET_WAS_ERROR(r)) { + break; + } + + limit = -target->distribution->limit; + num = 0; + r = package_openduplicateiterator(target, name, 0, &iterator); + if (!RET_WAS_ERROR(r) && iterator.cursor != NULL) do { + if (package_getsource(&iterator.current) && package_getversion(&iterator.current)) { + if (strcmp(source, iterator.current.pkgsource) == 0) { + retvalue r2; + if (num++ < limit) continue; + + fprintf(stderr, "Packages '%s' of source '%s' in '%s' have multiple versions. Remove '%s' that exceeds limit '%lld'!\n", + name, source, target->identifier, iterator.current.version, limit); + + r2 = archive_package(target, &iterator.current, NULL, causingrule, suitefrom); + RET_UPDATE(r, r2); + if (RET_WAS_ERROR(r2)) + continue; + r2 = package_remove_by_cursor(&iterator, logger, trackingdata); + RET_UPDATE(r, r2); + } + } + } while (package_next(&iterator)); + r = package_closeiterator(&iterator); + + free(source); + free(sourceversion); + break; + } + free(newcontrol); package_done(&old); From ce9e1953f7aa83a1e43df45d453e95bb972e3082 Mon Sep 17 00:00:00 2001 From: yumeyao Date: Fri, 11 Mar 2022 17:56:49 +0800 Subject: [PATCH 2/2] Fix multiversion test using limit=0 --- tests/basic.sh | 6 +++--- tests/multiversion.sh | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/basic.sh b/tests/basic.sh index 867c489c..a97ee755 100755 --- a/tests/basic.sh +++ b/tests/basic.sh @@ -293,9 +293,9 @@ Files: test_archive_move() { clear_distro - add_distro buster-archive "Limit: -1" + add_distro buster-archive "Limit: 0" add_distro buster "Limit: 1\nArchive: buster-archive" - add_distro buster-proposed "Limit: -1" + add_distro buster-proposed "Limit: 0" (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster VERSION=2.9 REVISION=-1 ../genpackage.sh) (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster VERSION=2.9 REVISION=-2 ../genpackage.sh) (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster VERSION=2.9 REVISION=-3 ../genpackage.sh) @@ -397,7 +397,7 @@ Files: test_archive_move_back() { clear_distro - add_distro buster-archive "Limit: -1" + add_distro buster-archive "Limit: 0" add_distro buster "Limit: 1\nArchive: buster-archive" (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster VERSION=2.9 REVISION=-1 ../genpackage.sh) (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster VERSION=2.9 REVISION=-2 ../genpackage.sh) diff --git a/tests/multiversion.sh b/tests/multiversion.sh index a7b83ee1..7018ad7f 100755 --- a/tests/multiversion.sh +++ b/tests/multiversion.sh @@ -26,7 +26,7 @@ oneTimeSetUp() { setUp() { create_repo - echo "Limit: -1" >> $REPO/conf/distributions + echo "Limit: 0" >> $REPO/conf/distributions } tearDown() { @@ -80,14 +80,14 @@ hello | 2.9-1 | buster | $ARCH" "$($REPREPRO -b $REPO ls hello)" test_copy_latest() { four_hellos - add_distro bullseye "Limit: -1" + add_distro bullseye "Limit: 0" call $REPREPRO $VERBOSE_ARGS -b $REPO copy bullseye buster hello hello assertEquals "bullseye|main|$ARCH: hello 2.9-10" "$($REPREPRO -b $REPO list bullseye)" } test_copy_specific() { four_hellos - add_distro bullseye "Limit: -1" + add_distro bullseye "Limit: 0" call $REPREPRO $VERBOSE_ARGS -b $REPO copy bullseye buster hello=2.9-10 hello=2.9-1 hello=2.9-10 assertEquals "\ bullseye|main|$ARCH: hello 2.9-10 @@ -96,7 +96,7 @@ bullseye|main|$ARCH: hello 2.9-1" "$($REPREPRO -b $REPO list bullseye)" test_remove_latest() { four_hellos - add_distro bullseye "Limit: -1" + add_distro bullseye "Limit: 0" call $REPREPRO $VERBOSE_ARGS -b $REPO copy bullseye buster hello=2.9-10 hello=2.9-1 hello=2.9-10 call $REPREPRO $VERBOSE_ARGS -b $REPO remove bullseye hello assertEquals "\ @@ -127,7 +127,7 @@ buster|main|$ARCH: hello 2.9-1 buster|main|$ARCH: kvm 1.2.1-9 buster|main|$ARCH: kvm 1.2.1-8" "$($REPREPRO -b $REPO list buster)" - add_distro bullseye "Limit: -1" + add_distro bullseye "Limit: 0" call $REPREPRO $VERBOSE_ARGS -b $REPO copy bullseye buster kvm assertEquals "bullseye|main|$ARCH: kvm 1.2.1-9" "$($REPREPRO -b $REPO list bullseye)" @@ -147,7 +147,7 @@ test_readd_distribution() { # Add distribution cp $REPO/conf/distributions $REPO/conf/distributions.backup - add_distro bullseye "Limit: -1" + add_distro bullseye "Limit: 0" call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb bullseye $PKGS/hello_2.9-2_${ARCH}.deb # Remove distribution @@ -156,7 +156,7 @@ test_readd_distribution() { # Re-add distribution again echo "I: Re-adding bullseye..." - add_distro bullseye "Limit: -1" + add_distro bullseye "Limit: 0" call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb bullseye $PKGS/hello_2.9-10_${ARCH}.deb assertEquals "bullseye|main|$ARCH: hello 2.9-10" "$($REPREPRO -b $REPO list bullseye)" } @@ -199,14 +199,14 @@ Files: test_reduce_limit_archive() { clear_distro add_distro buster-archive "Limit: 7" - add_distro buster "Limit: -1\nArchive: buster-archive" + add_distro buster "Limit: 0\nArchive: buster-archive" for revision in 1 2; do call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-${revision}_${ARCH}.deb done assertEquals "\ buster|main|${ARCH}: hello 2.9-2 buster|main|${ARCH}: hello 2.9-1" "$($REPREPRO -b $REPO list buster)" - sed -i 's/^Limit: -1$/Limit: 1/' $REPO/conf/distributions + sed -i 's/^Limit: 0$/Limit: 1/' $REPO/conf/distributions call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-10_${ARCH}.deb assertEquals "\ hello | 2.9-2 | buster-archive | $ARCH @@ -267,7 +267,7 @@ Architectures: $ARCH Components: main Update: icinga-stretch Log: icinga2.log -Limit: -1 +Limit: 0 EOF cat > "$REPO/conf/updates" <> 2.9-2)' assertEquals "\