about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-06-02T16·43+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-06-02T16·43+0200
commitd64e0c1b64dc20b02fae335397213d1ca17d9d56 (patch)
treef667d3e2249ed3b8240c7a48e895fb540c3be550
parenteda2aaae92c54892e70fff2958698e68a8204d35 (diff)
Make derivationFromPath work on diverted stores
-rw-r--r--src/libstore/derivations.cc14
-rw-r--r--src/libstore/local-fs-store.cc19
-rw-r--r--src/libstore/local-store.hh2
-rw-r--r--src/libstore/misc.cc8
-rw-r--r--src/libstore/store-api.hh2
5 files changed, 27 insertions, 18 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index 8067e412adf2..5590b99b36fa 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -3,6 +3,7 @@
 #include "globals.hh"
 #include "util.hh"
 #include "worker-protocol.hh"
+#include "fs-accessor.hh"
 
 
 namespace nix {
@@ -164,6 +165,19 @@ Derivation readDerivation(const Path & drvPath)
 }
 
 
+Derivation Store::derivationFromPath(const Path & drvPath)
+{
+    assertStorePath(drvPath);
+    ensurePath(drvPath);
+    auto accessor = getFSAccessor();
+    try {
+        return parseDerivation(accessor->readFile(drvPath));
+    } catch (FormatError & e) {
+        throw Error(format("error parsing derivation ‘%1%’: %2%") % drvPath % e.msg());
+    }
+}
+
+
 static void printString(string & res, const string & s)
 {
     res += '"';
diff --git a/src/libstore/local-fs-store.cc b/src/libstore/local-fs-store.cc
index a19e4ce5dbc9..b1b9dc29e40d 100644
--- a/src/libstore/local-fs-store.cc
+++ b/src/libstore/local-fs-store.cc
@@ -13,20 +13,21 @@ LocalFSStore::LocalFSStore(const Params & params)
 
 struct LocalStoreAccessor : public FSAccessor
 {
-    ref<Store> store;
+    ref<LocalFSStore> store;
 
-    LocalStoreAccessor(ref<Store> store) : store(store) { }
+    LocalStoreAccessor(ref<LocalFSStore> store) : store(store) { }
 
-    void assertStore(const Path & path)
+    Path toRealPath(const Path & path)
     {
         Path storePath = store->toStorePath(path);
         if (!store->isValidPath(storePath))
             throw Error(format("path ‘%1%’ is not a valid store path") % storePath);
+        return store->getRealStoreDir() + std::string(path, store->storeDir.size());
     }
 
     FSAccessor::Stat stat(const Path & path) override
     {
-        assertStore(path);
+        auto realPath = toRealPath(path);
 
         struct stat st;
         if (lstat(path.c_str(), &st)) {
@@ -47,7 +48,7 @@ struct LocalStoreAccessor : public FSAccessor
 
     StringSet readDirectory(const Path & path) override
     {
-        assertStore(path);
+        auto realPath = toRealPath(path);
 
         auto entries = nix::readDirectory(path);
 
@@ -60,20 +61,18 @@ struct LocalStoreAccessor : public FSAccessor
 
     std::string readFile(const Path & path) override
     {
-        assertStore(path);
-        return nix::readFile(path);
+        return nix::readFile(toRealPath(path));
     }
 
     std::string readLink(const Path & path) override
     {
-        assertStore(path);
-        return nix::readLink(path);
+        return nix::readLink(toRealPath(path));
     }
 };
 
 ref<FSAccessor> LocalFSStore::getFSAccessor()
 {
-    return make_ref<LocalStoreAccessor>(ref<Store>(shared_from_this()));
+    return make_ref<LocalStoreAccessor>(ref<LocalFSStore>(std::dynamic_pointer_cast<LocalFSStore>(shared_from_this())));
 }
 
 void LocalFSStore::narFromPath(const Path & path, Sink & sink)
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index 0c2766f667ec..7bfc4ad34c3f 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -261,6 +261,8 @@ private:
        specified by the ‘secret-key-files’ option. */
     void signPathInfo(ValidPathInfo & info);
 
+    Path getRealStoreDir() override { return realStoreDir; }
+
     friend class DerivationGoal;
     friend class SubstitutionGoal;
 };
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc
index 5c284d1b9ab2..114ab565e08c 100644
--- a/src/libstore/misc.cc
+++ b/src/libstore/misc.cc
@@ -7,14 +7,6 @@
 namespace nix {
 
 
-Derivation Store::derivationFromPath(const Path & drvPath)
-{
-    assertStorePath(drvPath);
-    ensurePath(drvPath);
-    return readDerivation(drvPath);
-}
-
-
 void Store::computeFSClosure(const Path & path,
     PathSet & paths, bool flipDirection, bool includeOutputs, bool includeDerivers)
 {
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index b665babc082c..7ef01ea93ed0 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -501,6 +501,8 @@ public:
     /* Register a permanent GC root. */
     Path addPermRoot(const Path & storePath,
         const Path & gcRoot, bool indirect, bool allowOutsideRootsDir = false);
+
+    virtual Path getRealStoreDir() { return storeDir; }
 };