summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/local-store.cc45
-rw-r--r--src/libstore/local-store.hh7
2 files changed, 33 insertions, 19 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index bb53caacc5..4629402fb1 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -655,24 +655,12 @@ void LocalStore::invalidatePath(const Path & path)
 }
 
 
-Path LocalStore::addToStore(const Path & _srcPath,
-    bool recursive, HashType hashAlgo, PathFilter & filter)
+Path LocalStore::addToStoreFromDump(const string & dump, const string & name,
+    bool recursive, HashType hashAlgo)
 {
-    Path srcPath(absPath(_srcPath));
-    debug(format("adding `%1%' to the store") % srcPath);
-
-    /* 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;
-    if (recursive) 
-        dumpPath(srcPath, sink, filter);
-    else
-        sink.s = readFile(srcPath);
-
-    Hash h = hashString(hashAlgo, sink.s);
+    Hash h = hashString(hashAlgo, dump);
 
-    Path dstPath = makeFixedOutputPath(recursive, hashAlgo, h, baseNameOf(srcPath));
+    Path dstPath = makeFixedOutputPath(recursive, hashAlgo, h, name);
 
     addTempRoot(dstPath);
 
@@ -688,10 +676,10 @@ Path LocalStore::addToStore(const Path & _srcPath,
             if (pathExists(dstPath)) deletePathWrapped(dstPath);
 
             if (recursive) {
-                StringSource source(sink.s);
+                StringSource source(dump);
                 restorePath(dstPath, source);
             } else
-                writeStringToFile(dstPath, sink.s);
+                writeStringToFile(dstPath, dump);
 
             canonicalisePathMetaData(dstPath);
 
@@ -701,7 +689,7 @@ Path LocalStore::addToStore(const Path & _srcPath,
                sha256); otherwise, compute it here. */
             registerValidPath(dstPath,
                 (recursive && hashAlgo == htSHA256) ? h :
-                (recursive ? hashString(htSHA256, sink.s) : hashPath(htSHA256, dstPath)),
+                (recursive ? hashString(htSHA256, dump) : hashPath(htSHA256, dstPath)),
                 PathSet(), "");
         }
 
@@ -712,6 +700,25 @@ Path LocalStore::addToStore(const Path & _srcPath,
 }
 
 
+Path LocalStore::addToStore(const Path & _srcPath,
+    bool recursive, HashType hashAlgo, PathFilter & filter)
+{
+    Path srcPath(absPath(_srcPath));
+    debug(format("adding `%1%' to the store") % srcPath);
+
+    /* 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;
+    if (recursive) 
+        dumpPath(srcPath, sink, filter);
+    else
+        sink.s = readFile(srcPath);
+
+    return addToStoreFromDump(sink.s, baseNameOf(srcPath), recursive, hashAlgo);
+}
+
+
 Path LocalStore::addTextToStore(const string & name, const string & s,
     const PathSet & references)
 {
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index 77e46fc3cc..f201ddbde9 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -93,6 +93,13 @@ public:
         bool recursive = true, HashType hashAlgo = htSHA256,
         PathFilter & filter = defaultPathFilter);
 
+    /* Like addToStore(), but the contents of the path are contained
+       in `dump', which is either a NAR serialisation (if recursive ==
+       true) or simply the contents of a regular file (if recursive ==
+       false). */
+    Path addToStoreFromDump(const string & dump, const string & name,
+        bool recursive = true, HashType hashAlgo = htSHA256);
+
     Path addTextToStore(const string & name, const string & s,
         const PathSet & references);