if a suite name was specified, use the matching apt index to figure out the package set to install

This commit is contained in:
Johannes 'josch' Schauer 2020-11-14 23:25:07 +01:00
parent 21a26b5dac
commit 9d32dee3f5
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -1958,11 +1958,30 @@ sub run_download() {
) )
) { ) {
my %ess_pkgs; my %ess_pkgs;
open(my $pipe_apt, '-|', 'apt-get', 'indextargets', '--format', my %ess_pkgs_target;
'$(FILENAME)', 'Created-By: Packages') my @pkgs_to_install_target;
or error "cannot start apt-get indextargets: $!"; my $num_indices = 0;
while (my $fname = <$pipe_apt>) { open(
chomp $fname; my $pipe_apt,
'-|',
'apt-get',
'indextargets',
'--format',
('$(CODENAME)' . "\t" . '$(SUITE)' . "\t" . '$(FILENAME)'),
'Created-By: Packages'
) or error "cannot start apt-get indextargets: $!";
while (my $line = <$pipe_apt>) {
chomp $line;
$num_indices++;
my ($codename, $suite, $fname) = split /\t/, $line, 3;
my $suite_matches = 0;
if (
defined $options->{suite}
and
($options->{suite} eq $codename or $options->{suite} eq $suite)
) {
$suite_matches = 1;
}
open(my $pipe_cat, '-|', '/usr/lib/apt/apt-helper', 'cat-file', open(my $pipe_cat, '-|', '/usr/lib/apt/apt-helper', 'cat-file',
$fname) $fname)
or error "cannot start apt-helper cat-file: $!"; or error "cannot start apt-helper cat-file: $!";
@ -1995,6 +2014,9 @@ sub run_download() {
# processing and we can handle it now # processing and we can handle it now
if ($ess eq 'yes') { if ($ess eq 'yes') {
$ess_pkgs{$pkgname} = (); $ess_pkgs{$pkgname} = ();
if ($suite_matches) {
$ess_pkgs_target{$pkgname} = ();
}
} elsif ($options->{variant} eq 'essential') { } elsif ($options->{variant} eq 'essential') {
# for this variant we are only interested in the # for this variant we are only interested in the
# essential packages # essential packages
@ -2013,6 +2035,9 @@ sub run_download() {
('important', 'required', 'buildd', 'minbase') ('important', 'required', 'buildd', 'minbase')
) { ) {
push @pkgs_to_install, $pkgname; push @pkgs_to_install, $pkgname;
if ($suite_matches) {
push @pkgs_to_install_target, $pkgname;
}
} }
} elsif ($prio eq 'important') { } elsif ($prio eq 'important') {
if ( if (
@ -2020,11 +2045,17 @@ sub run_download() {
('required', 'buildd', 'minbase') ('required', 'buildd', 'minbase')
) { ) {
push @pkgs_to_install, $pkgname; push @pkgs_to_install, $pkgname;
if ($suite_matches) {
push @pkgs_to_install_target, $pkgname;
}
} }
} elsif ($prio eq 'required') { } elsif ($prio eq 'required') {
# required packages are part of all sets except # required packages are part of all sets except
# essential and apt # essential and apt
push @pkgs_to_install, $pkgname; push @pkgs_to_install, $pkgname;
if ($suite_matches) {
push @pkgs_to_install_target, $pkgname;
}
} else { } else {
error "unknown priority: $prio"; error "unknown priority: $prio";
} }
@ -2045,6 +2076,33 @@ sub run_download() {
close $pipe_apt; close $pipe_apt;
$? == 0 or error "apt-get indextargets failed: $?"; $? == 0 or error "apt-get indextargets failed: $?";
# comparing the size of both arrays is sufficient because items are
# either only added to one or to both
if (defined $options->{suite} and $num_indices > 1) {
if (scalar keys %ess_pkgs_target > 0
and keys %ess_pkgs != %ess_pkgs_target) {
info( "multiple sources defined, using those matching "
. "'$options->{suite}' to find essential packages");
%ess_pkgs = %ess_pkgs_target;
}
if (scalar @pkgs_to_install_target > 0
and @pkgs_to_install != @pkgs_to_install_target) {
if ($options->{variant} eq 'essential') {
error "logic error";
} elsif (
any { $_ eq $options->{variant} }
('standard', 'important', 'required', 'buildd', 'minbase')
) {
info( "multiple sources defined -- using those matching "
. "'$options->{suite}' to find packages for variant "
. "'$options->{variant}'");
@pkgs_to_install = @pkgs_to_install_target;
} else {
error "unknown variant: $options->{variant}";
}
}
}
debug "Identified the following Essential:yes packages:"; debug "Identified the following Essential:yes packages:";
foreach my $pkg (sort keys %ess_pkgs) { foreach my $pkg (sort keys %ess_pkgs) {
debug " $pkg"; debug " $pkg";
@ -4512,9 +4570,9 @@ sub main() {
} }
{ {
my $suite; $options->{suite} = undef;
if (scalar @ARGV > 0) { if (scalar @ARGV > 0) {
$suite = shift @ARGV; $options->{suite} = shift @ARGV;
if (scalar @ARGV > 0) { if (scalar @ARGV > 0) {
$options->{target} = shift @ARGV; $options->{target} = shift @ARGV;
} else { } else {
@ -4527,7 +4585,7 @@ sub main() {
} }
my $sourceslists = []; my $sourceslists = [];
if (!defined $suite) { if (!defined $options->{suite}) {
# If no suite was specified, then the whole sources.list has to # If no suite was specified, then the whole sources.list has to
# come from standard input # come from standard input
info "Reading sources.list from standard input..."; info "Reading sources.list from standard input...";
@ -4572,7 +4630,8 @@ sub main() {
my $signedby = ''; my $signedby = '';
my %suite_by_vendor = get_suite_by_vendor(); my %suite_by_vendor = get_suite_by_vendor();
{ {
my $keyring = get_keyring_by_suite($suite, \%suite_by_vendor); my $keyring
= get_keyring_by_suite($options->{suite}, \%suite_by_vendor);
if (!defined $keyring) { if (!defined $keyring) {
last; last;
} }
@ -4724,7 +4783,11 @@ sub main() {
}; };
} }
} elsif ($arg =~ /:\/\//) { } elsif ($arg =~ /:\/\//) {
my $content = "deb$signedby $arg $suite $compstr\n"; my $content = join ' ',
(
"deb$signedby",
$arg, $options->{suite}, "$compstr\n"
);
# if last entry is of same type and without filename, # if last entry is of same type and without filename,
# then append # then append
if ( scalar @{$sourceslists} > 0 if ( scalar @{$sourceslists} > 0
@ -4770,7 +4833,8 @@ sub main() {
} }
} else { } else {
my $sourceslist my $sourceslist
= get_sourceslist_by_suite($suite, $options->{nativearch}, = get_sourceslist_by_suite($options->{suite},
$options->{nativearch},
$signedby, $compstr, \%suite_by_vendor); $signedby, $compstr, \%suite_by_vendor);
push @{$sourceslists}, push @{$sourceslists},
{ {