about summary refs log tree commit diff
path: root/scripts/download-from-binary-cache.pl.in
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-01T22·46-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-01T22·46-0400
commitf4190c38bac1efdbfec9b1ff9c524808d23fe1cc (patch)
tree2cd3282069ec9d3a5edbb251ab344a293dd4b0ec /scripts/download-from-binary-cache.pl.in
parent000132cbd1624a681a8114a117de07a56a7eed4e (diff)
Allow both bzip2 and xz compression
Diffstat (limited to 'scripts/download-from-binary-cache.pl.in')
-rw-r--r--scripts/download-from-binary-cache.pl.in19
1 files changed, 14 insertions, 5 deletions
diff --git a/scripts/download-from-binary-cache.pl.in b/scripts/download-from-binary-cache.pl.in
index ccd28eafc6d4..d121f2fc3151 100644
--- a/scripts/download-from-binary-cache.pl.in
+++ b/scripts/download-from-binary-cache.pl.in
@@ -4,7 +4,7 @@ use strict;
 use Nix::Config;
 use Nix::Store;
 
-my @binaryCacheUrls = ("file:///tmp/binary-cache");
+my @binaryCacheUrls = ("file:///tmp/binary-cache2");
 
 sub getInfoFrom {
     my ($storePath, $pathHash, $binaryCacheUrl) = @_;
@@ -15,14 +15,15 @@ sub getInfoFrom {
         print STDERR "GOT CURL REPLY ", $? >> 8, "\n";
         return undef;
     }
-    my ($storePath2, $url, $fileHash, $fileSize, $narHash, $narSize, $deriver);
+    my ($storePath2, $url, $compression, $fileHash, $fileSize, $narHash, $narSize, $deriver);
     my @refs;
     foreach my $line (split "\n", $s) {
         $line =~ /^(.*): (.*)$/ or return undef;
         if ($1 eq "StorePath") { $storePath2 = $2; }
         elsif ($1 eq "URL") { $url = $2; }
-        elsif ($1 eq "CompressedHash") { $fileHash = $2; }
-        elsif ($1 eq "CompressedSize") { $fileSize = int($2); }
+        elsif ($1 eq "Compression") { $compression = $2; }
+        elsif ($1 eq "FileHash") { $fileHash = $2; }
+        elsif ($1 eq "FileSize") { $fileSize = int($2); }
         elsif ($1 eq "NarHash") { $narHash = $2; }
         elsif ($1 eq "NarSize") { $narSize = int($2); }
         elsif ($1 eq "References") { @refs = split / /, $2; }
@@ -34,6 +35,7 @@ sub getInfoFrom {
     }
     return
         { url => $url
+        , compression => ($compression || "bzip2")
         , fileHash => $fileHash
         , fileSize => $fileSize
         , narHash => $narHash
@@ -64,7 +66,14 @@ sub downloadBinary {
     cache: foreach my $binaryCacheUrl (@binaryCacheUrls) {
         my $info = getInfoFrom($storePath, $pathHash, $binaryCacheUrl);
         if (defined $info) {
-            if (system("$Nix::Config::curl --fail --location $binaryCacheUrl/$info->{url} | $Nix::Config::xz -d | $Nix::Config::binDir/nix-store --restore $storePath") == 0) {
+            my $decompressor;
+            if ($info->{compression} eq "bzip2") { $decompressor = "$Nix::Config::bzip2 -d"; }
+            elsif ($info->{compression} eq "xz") { $decompressor = "$Nix::Config::xz -d"; }
+            else {
+                print STDERR "unknown compression method ‘$info->{compression}’\n";
+                next;
+            }
+            if (system("$Nix::Config::curl --fail --location $binaryCacheUrl/$info->{url} | $decompressor | $Nix::Config::binDir/nix-store --restore $storePath") == 0) {
                 return 1;
             }
         }