about summary refs log tree commit diff
path: root/src/libstore/binary-cache-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-24T15·52+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-24T15·52+0100
commit9ccbd55c5b55b5530e61fd20476d9f20fd45e074 (patch)
tree6a54e295af747d97bbd6c96cd43da478da51406c /src/libstore/binary-cache-store.cc
parent30e9d0151699206579df3f442e8517a2f8458cc2 (diff)
BinaryCacheStore: Implement addToStore()
So now you can do

  $ NIX_REMOTE=file:///tmp/binary-cache nix-instantiate '<nixpkgs>' -A hello

and lots of other operations.
Diffstat (limited to 'src/libstore/binary-cache-store.cc')
-rw-r--r--src/libstore/binary-cache-store.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc
index 6d40c70a3675..dc086fe9cf4e 100644
--- a/src/libstore/binary-cache-store.cc
+++ b/src/libstore/binary-cache-store.cc
@@ -24,6 +24,10 @@ BinaryCacheStore::BinaryCacheStore(std::shared_ptr<Store> localStore,
         auto key = PublicKey(readFile(publicKeyFile));
         publicKeys->emplace(key.name, key);
     }
+
+    StringSink sink;
+    sink << narVersionMagic1;
+    narMagic = sink.s;
 }
 
 void BinaryCacheStore::init()
@@ -55,6 +59,8 @@ void BinaryCacheStore::addToCache(const ValidPathInfo & info,
     auto narInfoFile = narInfoFileFor(info.path);
     if (fileExists(narInfoFile)) return;
 
+    assert(nar.compare(0, narMagic.size(), narMagic) == 0);
+
     auto narInfo = make_ref<NarInfo>(info);
 
     narInfo->narSize = nar.size();
@@ -261,6 +267,50 @@ void BinaryCacheStore::querySubstitutablePathInfos(const PathSet & paths,
         localStore->querySubstitutablePathInfos(left, infos);
 }
 
+Path BinaryCacheStore::addToStore(const string & name, const Path & srcPath,
+    bool recursive, HashType hashAlgo, PathFilter & filter, bool repair)
+{
+    // FIXME: some cut&paste from LocalStore::addToStore().
+
+    /* Read the whole path into memory. This is not a very scalable
+       method for very large paths, but `copyPath' is mainly used for
+       small files. */
+    StringSink sink;
+    Hash h;
+    if (recursive) {
+        dumpPath(srcPath, sink, filter);
+        h = hashString(hashAlgo, sink.s);
+    } else {
+        auto s = readFile(srcPath);
+        dumpString(s, sink);
+        h = hashString(hashAlgo, s);
+    }
+
+    ValidPathInfo info;
+    info.path = makeFixedOutputPath(recursive, hashAlgo, h, name);
+
+    if (repair || !isValidPath(info.path))
+        addToCache(info, sink.s);
+
+    return info.path;
+}
+
+Path BinaryCacheStore::addTextToStore(const string & name, const string & s,
+    const PathSet & references, bool repair)
+{
+    ValidPathInfo info;
+    info.path = computeStorePathForText(name, s, references);
+    info.references = references;
+
+    if (repair || !isValidPath(info.path)) {
+        StringSink sink;
+        dumpString(s, sink);
+        addToCache(info, sink.s);
+    }
+
+    return info.path;
+}
+
 void BinaryCacheStore::buildPaths(const PathSet & paths, BuildMode buildMode)
 {
     for (auto & storePath : paths) {