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>2013-04-23T10·43+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-04-23T10·43+0200
commitc642441beb504278819e43914516b5eda30f2c15 (patch)
treefef60b9b3e1521342e6f944cbfd3e2057647a47a /scripts/download-from-binary-cache.pl.in
parent05420e788315f04212fe936313b3ff7b580a206c (diff)
Test NAR info caching
Diffstat (limited to 'scripts/download-from-binary-cache.pl.in')
-rw-r--r--scripts/download-from-binary-cache.pl.in16
1 files changed, 12 insertions, 4 deletions
diff --git a/scripts/download-from-binary-cache.pl.in b/scripts/download-from-binary-cache.pl.in
index 03c331a636dd..68414ea63ad1 100644
--- a/scripts/download-from-binary-cache.pl.in
+++ b/scripts/download-from-binary-cache.pl.in
@@ -27,6 +27,8 @@ my $didExpiration = 0;
 my $debug = ($ENV{"NIX_DEBUG_SUBST"} // "") eq 1;
 open(STDERR, ">>/dev/tty") if $debug;
 
+my $cacheFileURLs = ($ENV{"_NIX_CACHE_FILE_URLS"} // "") eq 1; # for testing
+
 my ($dbh, $queryCache, $insertNAR, $queryNAR, $insertNARExistence, $queryNARExistence, $expireNARExistence);
 
 my $curlm = WWW::Curl::Multi->new;
@@ -267,6 +269,12 @@ sub getAvailableCaches {
 }
 
 
+sub shouldCache {
+    my ($url) = @_;
+    return $cacheFileURLs || $url !~ /^file:/;
+}
+
+
 sub processNARInfo {
     my ($storePath, $cache, $request) = @_;
 
@@ -276,7 +284,7 @@ sub processNARInfo {
                 ($request->{result} != 0 ? "Curl error $request->{result}" : "HTTP status $request->{httpStatus}") . ")\n";
         } else {
             $insertNARExistence->execute($cache->{id}, basename($storePath), 0, time())
-                unless $request->{url} =~ /^file:/;
+                if shouldCache $request->{url};
         }
         return undef;
     }
@@ -289,7 +297,7 @@ sub processNARInfo {
         $cache->{id}, basename($storePath), $narInfo->{url}, $narInfo->{compression},
         $narInfo->{fileHash}, $narInfo->{fileSize}, $narInfo->{narHash}, $narInfo->{narSize},
         join(" ", @{$narInfo->{refs}}), $narInfo->{deriver}, $narInfo->{system}, time())
-        unless $request->{url} =~ /^file:/;
+        if shouldCache $request->{url};
 
     return $narInfo;
 }
@@ -455,12 +463,12 @@ sub printSubstitutablePaths {
                         ($request->{result} != 0 ? "Curl error $request->{result}" : "HTTP status $request->{httpStatus}") . ")\n";
                 } else {
                     $insertNARExistence->execute($cache->{id}, basename($request->{storePath}), 0, time())
-                        unless $request->{url} =~ /^file:/;
+                        if shouldCache $request->{url};
                 }
                 push @left2, $request->{storePath};
             } else {
                 $insertNARExistence->execute($cache->{id}, basename($request->{storePath}), 1, time())
-                    unless $request->{url} =~ /^file:/;
+                    if shouldCache $request->{url};
                 print "$request->{storePath}\n";
             }
         }