Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple versions under same source package #23

Open
wants to merge 2 commits into
base: multiple-versions-debian
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion distribution.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions target.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions tests/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions tests/multiversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ oneTimeSetUp() {

setUp() {
create_repo
echo "Limit: -1" >> $REPO/conf/distributions
echo "Limit: 0" >> $REPO/conf/distributions
}

tearDown() {
Expand Down Expand Up @@ -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
Expand All @@ -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 "\
Expand Down Expand Up @@ -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)"

Expand All @@ -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
Expand All @@ -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)"
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -267,7 +267,7 @@ Architectures: $ARCH
Components: main
Update: icinga-stretch
Log: icinga2.log
Limit: -1
Limit: 0
EOF
cat > "$REPO/conf/updates" <<EOF
Name: icinga-stretch
Expand Down Expand Up @@ -339,7 +339,7 @@ buster|main|$ARCH: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"

test_movefilter_specific() {
four_hellos
add_distro bullseye "Limit: -1"
add_distro bullseye "Limit: 0"
$REPREPRO -b $REPO export bullseye
call $REPREPRO $VERBOSE_ARGS -b $REPO movefilter bullseye buster 'Package (= hello), $Version (>> 2.9-2)'
assertEquals "\
Expand Down