This commit is contained in:
Eelco Dolstra 2012-07-08 18:39:07 -04:00
parent 11800e6198
commit 400e556b34

View file

@ -230,7 +230,7 @@ sub getCacheId {
sub cachedGetInfoFrom { sub cachedGetInfoFrom {
my ($storePath, $pathHash, $binaryCacheUrl) = @_; my ($storePath, $binaryCacheUrl) = @_;
$queryNAR->execute(getCacheId($binaryCacheUrl), basename($storePath)); $queryNAR->execute(getCacheId($binaryCacheUrl), basename($storePath));
my $res = $queryNAR->fetchrow_hashref(); my $res = $queryNAR->fetchrow_hashref();
@ -260,16 +260,22 @@ sub printInfo {
} }
sub infoUrl {
my ($binaryCacheUrl, $storePath) = @_;
my $pathHash = substr(basename($storePath), 0, 32);
my $infoUrl = "$binaryCacheUrl/$pathHash.narinfo";
}
sub printInfoParallel { sub printInfoParallel {
my @paths = @_; my @paths = @_;
# First print all paths for which we have cached info. # First print all paths for which we have cached info.
my @left; my @left;
foreach my $storePath (@paths) { foreach my $storePath (@paths) {
my $pathHash = substr(basename($storePath), 0, 32);
my $found = 0; my $found = 0;
foreach my $binaryCacheUrl (@binaryCacheUrls) { foreach my $binaryCacheUrl (@binaryCacheUrls) {
my $info = cachedGetInfoFrom($storePath, $pathHash, $binaryCacheUrl); my $info = cachedGetInfoFrom($storePath, $binaryCacheUrl);
if (defined $info) { if (defined $info) {
printInfo($storePath, $info); printInfo($storePath, $info);
$found = 1; $found = 1;
@ -286,13 +292,11 @@ sub printInfoParallel {
my @left2; my @left2;
%requests = (); %requests = ();
foreach my $storePath (@left) { foreach my $storePath (@left) {
my $pathHash = substr(basename($storePath), 0, 32);
if (negativeHit($storePath, $binaryCacheUrl)) { if (negativeHit($storePath, $binaryCacheUrl)) {
push @left2, $storePath; push @left2, $storePath;
next; next;
} }
my $infoUrl = "$binaryCacheUrl/$pathHash.narinfo"; addRequest($storePath, infoUrl($binaryCacheUrl, $storePath));
addRequest($storePath, $infoUrl);
} }
processRequests; processRequests;
@ -314,14 +318,12 @@ sub printInfoParallel {
sub downloadBinary { sub downloadBinary {
my ($storePath) = @_; my ($storePath) = @_;
my $pathHash = substr(basename($storePath), 0, 32); foreach my $binaryCacheUrl (@binaryCacheUrls) {
my $info = cachedGetInfoFrom($storePath, $binaryCacheUrl);
cache: foreach my $binaryCacheUrl (@binaryCacheUrls) {
my $info = cachedGetInfoFrom($storePath, $pathHash, $binaryCacheUrl);
unless (defined $info) { unless (defined $info) {
next if negativeHit($storePath, $binaryCacheUrl); next if negativeHit($storePath, $binaryCacheUrl);
my $request = addRequest($storePath, "$binaryCacheUrl/$pathHash.narinfo"); my $request = addRequest($storePath, infoUrl($binaryCacheUrl, $storePath));
processRequests; processRequests;
$info = processNARInfo($storePath, $binaryCacheUrl, $request); $info = processNARInfo($storePath, $binaryCacheUrl, $request);
} }
@ -368,8 +370,6 @@ if ($ARGV[0] eq "--query") {
my $storePath = <STDIN>; chomp $storePath; my $storePath = <STDIN>; chomp $storePath;
# FIXME: want to give correct info here, but it's too slow. # FIXME: want to give correct info here, but it's too slow.
print "0\n"; print "0\n";
#my $info = getInfo($storePath);
#if (defined $info) { print "1\n"; } else { print "0\n"; }
} }
elsif ($cmd eq "info") { elsif ($cmd eq "info") {