]> git.proxmox.com Git - dab.git/commitdiff
try all available compressors for Packages
authorStoiko Ivanov <s.ivanov@proxmox.com>
Wed, 14 Jul 2021 14:49:25 +0000 (16:49 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 14 Jul 2021 15:37:08 +0000 (17:37 +0200)
Some repositories (e.g. debian-security) only offer .xz compressed
Packages, others (e.g. promox repositories) only .gz compressed ones.

Make the compressors an array and try them in order until successful

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
DAB.pm

diff --git a/DAB.pm b/DAB.pm
index 26db7ad9eb3b97263f3de6b5ab617e2a87222a30..c540237b106d4da5f1b732856fbb5ddaf2aa7233 100644 (file)
--- a/DAB.pm
+++ b/DAB.pm
@@ -618,17 +618,16 @@ sub initialize {
     my $logfd = $self->{logfd} = IO::File->new (">$self->{logfile}") ||
        die "unable to open log file";
 
-    # FIXME: seems a bit like a hacky way??
-    my $COMPRESSOR = {
-       ext => 'gz',
-       decomp => 'gzip -d',
-    };
-    if ($self->{config}->{suite} eq 'bullseye') {
-       $COMPRESSOR = {
+    my $COMPRESSORS = [
+       {
            ext => 'xz',
            decomp => 'xz -d',
-       };
-    }
+       },
+       {
+           ext => 'gz',
+           decomp => 'gzip -d',
+       },
+    ];
 
     foreach my $ss (@{$self->{sources}}) {
        my $src = $ss->{mirror} || $ss->{source};
@@ -645,12 +644,21 @@ sub initialize {
            warn "Release info ignored\n";
        };
 
-       foreach my $comp (@{$ss->{comp}}) {
-           $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$COMPRESSOR->{ext}";
-           $target = "$infodir/" . __url_to_filename ("$ss->{source}/$path");
-           my $pkgsrc = "$src/$path";
-           $self->download ($pkgsrc, $target);
-           $self->run_command ("$COMPRESSOR->{decomp} '$target'");
+       foreach my $compressor (@$COMPRESSORS) {
+           foreach my $comp (@{$ss->{comp}}) {
+               $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$compressor->{ext}";
+               $target = "$infodir/" . __url_to_filename ("$ss->{source}/$path");
+               my $pkgsrc = "$src/$path";
+               eval {
+                   $self->download ($pkgsrc, $target);
+                   $self->run_command ("$compressor->{decomp} '$target'");
+               };
+               if (my $err = $@) {
+                   print $logfd "could not download Packages.$compressor->{ext}\n";
+               } else {
+                   last;
+               }
+           }
        }
     }
 }