267
268
my ($package, $version) = @_;
270
my ($archpackage, $arch) = $package;
271
($package, $arch) = split(/:/, $package, 2);
269
273
my $qpackage = quotemeta($package);
270
274
my $qversion = quote_version($version) if $version;
273
my $apt = new IO::File("LC_ALL=C apt-cache policy $package |") or die "$!";
277
my $apt = IO::File->new("LC_ALL=C apt-cache policy $archpackage |") or die "$!";
274
278
OUTER: while (<$apt>) {
275
279
if (not $version and /^ Candidate: (.+)/) {
289
293
unless ($version) {
290
die "$progname: $package has no installation candidate\n";
294
die "$progname: $archpackage has no installation candidate\n";
292
296
unless (@hosts) {
293
die "$progname: no hostnames in apt-cache policy $package for version $version found\n";
297
die "$progname: no hostnames in apt-cache policy $archpackage for version $version found\n";
296
$apt = new IO::File("LC_ALL=C apt-cache show $package=$version |")
300
$apt = IO::File->new("LC_ALL=C apt-cache show $archpackage=$version |")
298
302
my ($v, $p, $filename, $md5sum);
483
487
# case 2a: --all srcpackage[=version]
484
} elsif ($opt->{'all'} and $arg =~ /^([a-z0-9.+-]{2,})(?:=([a-zA-Z0-9.:~+-]+))?$/) {
485
my ($source, $version) = ($1, $2);
488
} elsif ($opt->{'all'} and $arg =~ /^([a-z0-9.+-:]{2,})(?:=([a-zA-Z0-9.:~+-]+))?$/) {
489
my ($source, $version, $arch) = ($1, $2);
490
($source, $arch) = split(/:/, $source, 2);
486
491
my $cmd = "apt-cache showsrc $source";
487
#$cmd .= "=$version" if ($version); # unfortunately =version doesn't work here
490
next unless /^Binary: (.*)/;
491
my @packages = split (/, /, $1);
492
foreach my $package (@packages) {
493
eval { apt_get ($package, $version) } or print "$@";
492
# unfortunately =version doesn't work here, and even if it did, was the
493
# user referring to the source version or the binary version? The code
494
# assumes binary version.
495
#$cmd .= "=$version" if ($version);
496
open my $showsrc, '-|', $cmd;
497
my $c = Dpkg::Control->new(type => CTRL_INDEX_SRC);
498
while ($c->parse($showsrc, $cmd)) {
500
my @packages = grep { $_ } split /\n/, $c->{'Package-List'};
501
# Find all packages whose architecture is either 'all', 'any',
502
# or the given architecture. The Package-List lines are
503
# $pkg $debtype $section $priority arch=$archlist
504
foreach my $package (@packages) {
505
$package =~ s/^\s*//;
510
$archs) = split(/\s+/, $package, 5);
511
if ($archs =~ m/all/) {
512
eval { apt_get($binary, $version) } or print "$@";
514
elsif ($archs =~ m/any|[=,]$arch/) {
515
eval { apt_get("$binary:$arch", $version) } or print "$@";
520
my @packages = split /, /, $c->{Binary};
521
foreach my $package (@packages) {
522
eval { apt_get ($package, $version) } or print "$@";
499
529
# case 2b: package[=version]
500
} elsif ($arg =~ /^([a-z0-9.+-]{2,})(?:=([a-zA-Z0-9.:~+-]+))?$/) {
530
} elsif ($arg =~ /^([a-z0-9.+-:]{2,})(?:=([a-zA-Z0-9.:~+-]+))?$/) {
567
597
=item B<-a>, B<--all>
569
599
Interpret I<package> as a source package name, and download all binaries as
570
found in the output of "apt-cache showsrc I<package>".
600
found in the output of "apt-cache showsrc I<package>". If I<package> is
601
arch-qualified, then only binary packages which are "Arch: all", "Arch: any",
602
or "Arch: $arch" will be downloaded.
572
604
=item B<-b>, B<--backup>