nix-super/scripts/readmanifest.pm.in

73 lines
1.6 KiB
Perl
Raw Normal View History

use strict;
sub processURL {
my $manifest = shift;
my $url = shift;
my $storePaths2urls = shift;
my $urls2hashes = shift;
my $successors = shift;
$url =~ s/\/$//;
print "obtaining list of Nix archives at $url...\n";
system("@curl@ --fail --silent --show-error --location --max-redirs 20 " .
2004-10-20 17:05:48 +03:00
"'$url' > '$manifest'") == 0
or die "curl failed: $?";
open MANIFEST, "<$manifest";
my $inside = 0;
my $storePath;
my $narurl;
my $hash;
my @preds;
while (<MANIFEST>) {
chomp;
s/\#.*$//g;
next if (/^$/);
if (!$inside) {
if (/^\{$/) {
$inside = 1;
undef $storePath;
undef $narurl;
undef $hash;
@preds = ();
}
else { die "bad line: $_"; }
} else {
if (/^\}$/) {
$inside = 0;
$$storePaths2urls{$storePath} = $narurl;
$$urls2hashes{$narurl} = $hash;
foreach my $p (@preds) {
$$successors{$p} = $storePath;
}
}
elsif (/^\s*StorePath:\s*(\/\S+)\s*$/) {
$storePath = $1;
}
elsif (/^\s*NarURL:\s*(\S+)\s*$/) {
$narurl = $1;
}
elsif (/^\s*MD5:\s*(\S+)\s*$/) {
$hash = $1;
}
elsif (/^\s*SuccOf:\s*(\/\S+)\s*$/) {
push @preds, $1;
}
else { die "bad line: $_"; }
}
}
close MANIFEST;
}
return 1;