about summary refs log tree commit diff
path: root/perl/lib
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-17T22·55-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-17T22·55-0400
commitccc52adfb2121ade510d35dc9b91193af9fa731e (patch)
treec6314b5198cdfbe9a21633e515203965ee431382 /perl/lib
parent220818f758d2facc194f567f35ca677ef79393bd (diff)
Add function queryPathFromHashPart()
To implement binary caches efficiently, Hydra needs to be able to map
the hash part of a store path (e.g. "gbg...zr7") to the full store
path (e.g. "/nix/store/gbg...kzr7-subversion-1.7.5").  (The binary
cache mechanism uses hash parts as a key for looking up store paths to
ensure privacy.)  However, doing a search in the Nix store for
/nix/store/<hash>* is expensive since it requires reading the entire
directory.  queryPathFromHashPart() prevents this by doing a cheap
database lookup.
Diffstat (limited to 'perl/lib')
-rw-r--r--perl/lib/Nix/Store.pm1
-rw-r--r--perl/lib/Nix/Store.xs11
2 files changed, 12 insertions, 0 deletions
diff --git a/perl/lib/Nix/Store.pm b/perl/lib/Nix/Store.pm
index 8312a732cdea..2e79c74fe290 100644
--- a/perl/lib/Nix/Store.pm
+++ b/perl/lib/Nix/Store.pm
@@ -14,6 +14,7 @@ our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
 
 our @EXPORT = qw(
     isValidPath queryReferences queryPathInfo queryDeriver queryPathHash
+    queryPathFromHashPart
     topoSortPaths computeFSClosure followLinksToStorePath exportPaths
     hashPath hashFile hashString
     addToStore makeFixedOutputPath
diff --git a/perl/lib/Nix/Store.xs b/perl/lib/Nix/Store.xs
index 2ebff5575616..76de674e6d5b 100644
--- a/perl/lib/Nix/Store.xs
+++ b/perl/lib/Nix/Store.xs
@@ -108,6 +108,17 @@ SV * queryPathInfo(char * path, int base32)
         }
 
 
+SV * queryPathFromHashPart(char * hashPart)
+    PPCODE:
+        try {
+            doInit();
+            Path path = store->queryPathFromHashPart(hashPart);
+            XPUSHs(sv_2mortal(newSVpv(path.c_str(), 0)));
+        } catch (Error & e) {
+            croak(e.what());
+        }
+
+
 SV * computeFSClosure(int flipDirection, int includeOutputs, ...)
     PPCODE:
         try {