aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/store-api.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/store-api.cc
parent0565b5f2b35dc153dc98e1e3bd37476aa13ee4f1 (diff)
* 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/store-api.cc')
-rw-r--r--src/libstore/store-api.cc40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index f1e7c3562..e00f01bfd 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -92,7 +92,45 @@ Path makeFixedOutputPath(bool recursive,
return makeStorePath("output:out", h, name);
}
-
+
+std::pair<Path, Hash> computeStorePathForPath(bool fixed, bool recursive,
+ string hashAlgo, const Path & 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);
+
+ return std::pair<Path, Hash>(dstPath, h);
+}
+
+
+Path computeStorePathForText(const string & suffix, const string & s)
+{
+ Hash hash = hashString(htSHA256, s);
+ return makeStorePath("text", hash, suffix);
+}
+
+
}