1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 04:21:16 +02:00

* 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).
This commit is contained in:
Eelco Dolstra 2006-12-01 18:00:01 +00:00
parent 0565b5f2b3
commit b0d8e05be1
5 changed files with 116 additions and 33 deletions

View file

@ -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);
}
}