pkgs_to_install might contain duplicates when multiple suites are used -- avoid that by using a hash instead of an array

This commit is contained in:
Johannes 'josch' Schauer 2020-11-15 22:58:26 +01:00
parent 94459eafbe
commit ad56754a2a
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -1825,7 +1825,7 @@ sub run_update() {
sub run_download() { sub run_download() {
my $options = shift; my $options = shift;
my @pkgs_to_install; my %pkgs_to_install;
for my $incl (@{ $options->{include} }) { for my $incl (@{ $options->{include} }) {
for my $pkg (split /[,\s]+/, $incl) { for my $pkg (split /[,\s]+/, $incl) {
# strip leading and trailing whitespace # strip leading and trailing whitespace
@ -1834,15 +1834,11 @@ sub run_download() {
if ($pkg eq '') { if ($pkg eq '') {
next; next;
} }
# do not append component if it's already in the list $pkgs_to_install{$pkg} = ();
if (any { $_ eq $pkg } @pkgs_to_install) {
next;
}
push @pkgs_to_install, $pkg;
} }
} }
if ($options->{variant} eq 'buildd') { if ($options->{variant} eq 'buildd') {
push @pkgs_to_install, 'build-essential'; $pkgs_to_install{'build-essential'} = ();
} }
# We use /var/cache/apt/archives/ to figure out which packages apt chooses # We use /var/cache/apt/archives/ to figure out which packages apt chooses
@ -1856,7 +1852,7 @@ sub run_download() {
if ( if (
!$options->{dryrun} !$options->{dryrun}
&& ((none { $_ eq $options->{variant} } ('extract', 'custom')) && ((none { $_ eq $options->{variant} } ('extract', 'custom'))
|| scalar @pkgs_to_install != 0) || scalar keys %pkgs_to_install != 0)
&& -d "$options->{root}/var/cache/apt/archives/" && -d "$options->{root}/var/cache/apt/archives/"
) { ) {
my $apt_archives = "/var/cache/apt/archives/"; my $apt_archives = "/var/cache/apt/archives/";
@ -1889,7 +1885,7 @@ sub run_download() {
# (essential variant) then we have to compute the package set ourselves. # (essential variant) then we have to compute the package set ourselves.
# Same if we want to install priority based variants. # Same if we want to install priority based variants.
if (any { $_ eq $options->{variant} } ('extract', 'custom')) { if (any { $_ eq $options->{variant} } ('extract', 'custom')) {
if (scalar @pkgs_to_install == 0) { if (scalar keys %pkgs_to_install == 0) {
info "nothing to download -- skipping..."; info "nothing to download -- skipping...";
return ([], []); return ([], []);
} }
@ -1913,7 +1909,7 @@ sub run_download() {
$options->{dryrun} ? '-oAPT::Get::Simulate=true' : (), $options->{dryrun} ? '-oAPT::Get::Simulate=true' : (),
'install' 'install'
], ],
PKGS => [@pkgs_to_install], PKGS => [keys %pkgs_to_install],
%result %result
}); });
} elsif ($options->{variant} eq 'apt') { } elsif ($options->{variant} eq 'apt') {
@ -1959,7 +1955,7 @@ sub run_download() {
) { ) {
my %ess_pkgs; my %ess_pkgs;
my %ess_pkgs_target; my %ess_pkgs_target;
my @pkgs_to_install_target; my %pkgs_to_install_target;
my $num_indices = 0; my $num_indices = 0;
open( open(
my $pipe_apt, my $pipe_apt,
@ -2034,9 +2030,9 @@ sub run_download() {
none { $_ eq $options->{variant} } none { $_ eq $options->{variant} }
('important', 'required', 'buildd', 'minbase') ('important', 'required', 'buildd', 'minbase')
) { ) {
push @pkgs_to_install, $pkgname; $pkgs_to_install{$pkgname} = ();
if ($suite_matches) { if ($suite_matches) {
push @pkgs_to_install_target, $pkgname; $pkgs_to_install_target{$pkgname} = ();
} }
} }
} elsif ($prio eq 'important') { } elsif ($prio eq 'important') {
@ -2044,17 +2040,17 @@ sub run_download() {
none { $_ eq $options->{variant} } none { $_ eq $options->{variant} }
('required', 'buildd', 'minbase') ('required', 'buildd', 'minbase')
) { ) {
push @pkgs_to_install, $pkgname; $pkgs_to_install{$pkgname} = ();
if ($suite_matches) { if ($suite_matches) {
push @pkgs_to_install_target, $pkgname; $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; $pkgs_to_install{$pkgname} = ();
if ($suite_matches) { if ($suite_matches) {
push @pkgs_to_install_target, $pkgname; $pkgs_to_install_target{$pkgname} = ();
} }
} else { } else {
error "unknown priority: $prio"; error "unknown priority: $prio";
@ -2085,8 +2081,8 @@ sub run_download() {
. "'$options->{suite}' to find essential packages"); . "'$options->{suite}' to find essential packages");
%ess_pkgs = %ess_pkgs_target; %ess_pkgs = %ess_pkgs_target;
} }
if (scalar @pkgs_to_install_target > 0 if (scalar keys %pkgs_to_install_target > 0
and @pkgs_to_install != @pkgs_to_install_target) { and keys %pkgs_to_install != keys %pkgs_to_install_target) {
if ($options->{variant} eq 'essential') { if ($options->{variant} eq 'essential') {
error "logic error"; error "logic error";
} elsif ( } elsif (
@ -2096,7 +2092,7 @@ sub run_download() {
info( "multiple sources defined -- using those matching " info( "multiple sources defined -- using those matching "
. "'$options->{suite}' to find packages for variant " . "'$options->{suite}' to find packages for variant "
. "'$options->{variant}'"); . "'$options->{variant}'");
@pkgs_to_install = @pkgs_to_install_target; %pkgs_to_install = %pkgs_to_install_target;
} else { } else {
error "unknown variant: $options->{variant}"; error "unknown variant: $options->{variant}";
} }
@ -2199,7 +2195,7 @@ sub run_download() {
# list before returning it. # list before returning it.
@essential_pkgs = sort @essential_pkgs; @essential_pkgs = sort @essential_pkgs;
return (\@pkgs_to_install, \@essential_pkgs, \@cached_debs); return ([keys %pkgs_to_install], \@essential_pkgs, \@cached_debs);
} }
sub run_extract() { sub run_extract() {