From 99f82456f3c7f589bd40cd64c9faba4ac73a99d8 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Mon, 28 Oct 2024 09:13:48 +0100 Subject: [PATCH] do not generate apt sources.list entry if SUITE is empty --- coverage.txt | 2 ++ mmdebstrap | 11 +++++++++++ tests/empty-suite | 13 +++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/empty-suite diff --git a/coverage.txt b/coverage.txt index 9e10836..cda7eb8 100644 --- a/coverage.txt +++ b/coverage.txt @@ -433,3 +433,5 @@ Modes: unshare Test: zombie-reaping Modes: unshare + +Test: empty-suite diff --git a/mmdebstrap b/mmdebstrap index 01841b0..2f18562 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -5265,6 +5265,10 @@ sub get_sourceslist_by_suite { my $compstr = 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 @ubuntustable = keys %{ $suite_by_vendor->{'ubuntu'} }; my @tanglustable = keys %{ $suite_by_vendor->{'tanglu'} }; @@ -6525,6 +6529,10 @@ sub main() { }; } } elsif ($arg =~ /:\/\//) { + if (!$options->{suite}) { + error( "cannot create sources.list entry for URI" + . "with empty suite"); + } my $content = join ' ', ( "deb$signedby", @@ -6580,6 +6588,9 @@ sub main() { error "invalid mirror: $arg"; } } + } elsif (!length($options->{suite})) { + warning + "cannot guess apt sources.list entry with empty suite name"; } else { my $sourceslist = get_sourceslist_by_suite($options->{suite}, diff --git a/tests/empty-suite b/tests/empty-suite new file mode 100644 index 0000000..411d456 --- /dev/null +++ b/tests/empty-suite @@ -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