From f4190c38bac1efdbfec9b1ff9c524808d23fe1cc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 1 Jul 2012 18:46:38 -0400 Subject: Allow both bzip2 and xz compression --- scripts/download-from-binary-cache.pl.in | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'scripts/download-from-binary-cache.pl.in') diff --git a/scripts/download-from-binary-cache.pl.in b/scripts/download-from-binary-cache.pl.in index ccd28eafc..d121f2fc3 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; } } -- cgit v1.2.3