* nix-pull: support bzipped manifests: when doing a nix-pull on $url,

try $url.bz2 first.
This commit is contained in:
Eelco Dolstra 2007-08-10 01:42:00 +00:00
parent 911bc01454
commit 4695f4edd6

View file

@ -7,8 +7,6 @@ use readmanifest;
my $tmpDir = tempdir("nix-pull.XXXXXX", CLEANUP => 1, TMPDIR => 1) my $tmpDir = tempdir("nix-pull.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory"; or die "cannot create a temporary directory";
#my $manifest = "$tmpDir/manifest";
my $binDir = $ENV{"NIX_BIN_DIR"}; my $binDir = $ENV{"NIX_BIN_DIR"};
$binDir = "@bindir@" unless defined $binDir; $binDir = "@bindir@" unless defined $binDir;
@ -33,16 +31,42 @@ my %patches;
my $skipWrongStore = 0; my $skipWrongStore = 0;
sub downloadFile {
my $url = shift;
$ENV{"PRINT_PATH"} = 1;
$ENV{"QUIET"} = 1;
my ($dummy, $path) = `@bindir@/nix-prefetch-url '$url'`;
chomp $path;
return $path;
}
sub processURL { sub processURL {
my $url = shift; my $url = shift;
$url =~ s/\/$//; $url =~ s/\/$//;
print "obtaining list of Nix archives at `$url'...\n";
$ENV{"PRINT_PATH"} = 1; my $manifest;
$ENV{"QUIET"} = 1;
my ($dummy, $manifest) = `@bindir@/nix-prefetch-url '$url'`; # First see if a bzipped manifest is available.
if (system("@curl@ --fail --silent --head '$url'.bz2 > /dev/null") == 0) {
print "obtaining list of Nix archives at `$url.bz2'...\n";
my $bzipped = downloadFile "$url.bz2";
$manifest = "$tmpDir/MANIFEST";
system("@bunzip2@ < $bzipped > $manifest") == 0
or die "cannot decompress manifest";
$manifest = (`$binDir/nix-store --add $manifest`
or die "cannot copy $manifest to the store");
chomp $manifest; chomp $manifest;
}
# Otherwise, just get the uncompressed manifest.
else {
print "obtaining list of Nix archives at `$url'...\n";
$manifest = downloadFile $url;
}
if (readManifest($manifest, \%narFiles, \%localPaths, \%patches) < 3) { if (readManifest($manifest, \%narFiles, \%localPaths, \%patches) < 3) {
die "manifest `$url' is too old (i.e., for Nix <= 0.7)\n"; die "manifest `$url' is too old (i.e., for Nix <= 0.7)\n";
@ -68,7 +92,7 @@ sub processURL {
my $finalPath = "$stateDir/manifests/$baseName-$hash.nixmanifest"; my $finalPath = "$stateDir/manifests/$baseName-$hash.nixmanifest";
system ("@coreutils@/ln", "-sfn", "$manifest", "$finalPath") == 0 system("@coreutils@/ln", "-sfn", "$manifest", "$finalPath") == 0
or die "cannot link `$finalPath to `$manifest'"; or die "cannot link `$finalPath to `$manifest'";
} }