do not generate apt sources.list entry if SUITE is empty

This commit is contained in:
Johannes Schauer Marin Rodrigues 2024-10-28 09:13:48 +01:00
parent 5055b1b44c
commit 99f82456f3
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1
3 changed files with 26 additions and 0 deletions

View file

@ -433,3 +433,5 @@ Modes: unshare
Test: zombie-reaping Test: zombie-reaping
Modes: unshare Modes: unshare
Test: empty-suite

View file

@ -5265,6 +5265,10 @@ sub get_sourceslist_by_suite {
my $compstr = shift; my $compstr = shift;
my $suite_by_vendor = shift; my $suite_by_vendor = shift;
if (!$suite) {
error "get_sourceslist_by_suite cannot operate with an empty suite";
}
my @debstable = keys %{ $suite_by_vendor->{'debian'} }; my @debstable = keys %{ $suite_by_vendor->{'debian'} };
my @ubuntustable = keys %{ $suite_by_vendor->{'ubuntu'} }; my @ubuntustable = keys %{ $suite_by_vendor->{'ubuntu'} };
my @tanglustable = keys %{ $suite_by_vendor->{'tanglu'} }; my @tanglustable = keys %{ $suite_by_vendor->{'tanglu'} };
@ -6525,6 +6529,10 @@ sub main() {
}; };
} }
} elsif ($arg =~ /:\/\//) { } elsif ($arg =~ /:\/\//) {
if (!$options->{suite}) {
error( "cannot create sources.list entry for URI"
. "with empty suite");
}
my $content = join ' ', my $content = join ' ',
( (
"deb$signedby", "deb$signedby",
@ -6580,6 +6588,9 @@ sub main() {
error "invalid mirror: $arg"; error "invalid mirror: $arg";
} }
} }
} elsif (!length($options->{suite})) {
warning
"cannot guess apt sources.list entry with empty suite name";
} else { } else {
my $sourceslist my $sourceslist
= get_sourceslist_by_suite($options->{suite}, = get_sourceslist_by_suite($options->{suite},

13
tests/empty-suite Normal file
View file

@ -0,0 +1,13 @@
#!/bin/sh
set -eu
export LC_ALL=C.UTF-8
export SOURCE_DATE_EPOCH={{ SOURCE_DATE_EPOCH }}
trap "rm -f /tmp/debian-chroot.tar" EXIT INT TERM
{{ CMD }} --variant={{ VARIANT }} --verbose \
--setup-hook='echo deb {{ MIRROR }} {{ DIST }} main >> "$1"/etc/apt/sources.list' \
'' /tmp/debian-chroot.tar
cmp ./cache/mmdebstrap-{{ DIST }}-{{ VARIANT }}.tar /tmp/debian-chroot.tar \
|| diffoscope ./cache/mmdebstrap-{{ DIST }}-{{ VARIANT }}.tar /tmp/debian-chroot.tar