summary refs log tree commit diff
path: root/src/libstore/local-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-12-01 18:00:01 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-12-01 18:00:01 +0000
commitb0d8e05be16e9887dbf3edcd6167c7f0b36dee5d (patch)
tree528ed2045ab784848cc70d87c851387d087b6163 /src/libstore/local-store.cc
parent0565b5f2b35dc153dc98e1e3bd37476aa13ee4f1 (diff)
downloadguix-b0d8e05be16e9887dbf3edcd6167c7f0b36dee5d.tar.gz
* More operations.
* addToStore() and friends: don't do a round-trip to the worker if
  we're only interested in the path (i.e., in read-only mode).

Diffstat (limited to 'src/libstore/local-store.cc')
-rw-r--r--src/libstore/local-store.cc31
1 files changed, 5 insertions, 26 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index e3f22a9c9e..ed948cf4e5 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -625,29 +625,10 @@ Path LocalStore::_addToStore(bool fixed, bool recursive,
     Path srcPath(absPath(_srcPath));
     debug(format("adding `%1%' to the store") % srcPath);
 
-    Hash h(htSHA256);
-    {
-        SwitchToOriginalUser sw;
-        h = hashPath(htSHA256, srcPath);
-    }
-
-    string baseName = baseNameOf(srcPath);
-
-    Path dstPath;
-    
-    if (fixed) {
-
-        HashType ht(parseHashType(hashAlgo));
-        Hash h2(ht);
-        {
-            SwitchToOriginalUser sw;
-            h2 = recursive ? hashPath(ht, srcPath) : hashFile(ht, srcPath);
-        }
-        
-        dstPath = makeFixedOutputPath(recursive, hashAlgo, h2, baseName);
-    }
-        
-    else dstPath = makeStorePath("source", h, baseName);
+    std::pair<Path, Hash> pr =
+        computeStorePathForPath(fixed, recursive, hashAlgo, srcPath);
+    Path & dstPath(pr.first);
+    Hash & h(pr.second);
 
     if (!readOnlyMode) addTempRoot(dstPath);
 
@@ -698,9 +679,7 @@ Path LocalStore::addToStoreFixed(bool recursive, string hashAlgo, const Path & s
 Path LocalStore::addTextToStore(const string & suffix, const string & s,
     const PathSet & references)
 {
-    Hash hash = hashString(htSHA256, s);
-
-    Path dstPath = makeStorePath("text", hash, suffix);
+    Path dstPath = computeStorePathForText(suffix, s);
     
     if (!readOnlyMode) addTempRoot(dstPath);