* Made addToStore() a lot more efficient: it no longer reads the path
being copied 3 times in the worst case. It doesn't run in constant space, but it didn't do that anyway.
This commit is contained in:
parent
64519cfd65
commit
1307b22223
2 changed files with 29 additions and 35 deletions
|
@ -257,9 +257,7 @@ static Hash hashDerivationModulo(EvalState & state, Derivation drv)
|
||||||
/* For other derivations, replace the inputs paths with recursive
|
/* For other derivations, replace the inputs paths with recursive
|
||||||
calls to this function.*/
|
calls to this function.*/
|
||||||
DerivationInputs inputs2;
|
DerivationInputs inputs2;
|
||||||
for (DerivationInputs::iterator i = drv.inputDrvs.begin();
|
foreach (DerivationInputs::const_iterator, i, drv.inputDrvs) {
|
||||||
i != drv.inputDrvs.end(); ++i)
|
|
||||||
{
|
|
||||||
Hash h = state.drvHashes[i->first];
|
Hash h = state.drvHashes[i->first];
|
||||||
if (h.type == htUnknown) {
|
if (h.type == htUnknown) {
|
||||||
Derivation drv2 = derivationFromPath(i->first);
|
Derivation drv2 = derivationFromPath(i->first);
|
||||||
|
|
|
@ -108,23 +108,6 @@ int LocalStore::getSchema()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void copyPath(const Path & src, const Path & dst, PathFilter & filter)
|
|
||||||
{
|
|
||||||
debug(format("copying `%1%' to `%2%'") % src % dst);
|
|
||||||
|
|
||||||
/* Dump an archive of the path `src' into a string buffer, then
|
|
||||||
restore the archive to `dst'. This is not a very good method
|
|
||||||
for very large paths, but `copyPath' is mainly used for small
|
|
||||||
files. */
|
|
||||||
|
|
||||||
StringSink sink;
|
|
||||||
dumpPath(src, sink, filter);
|
|
||||||
|
|
||||||
StringSource source(sink.s);
|
|
||||||
restorePath(dst, source);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void canonicalisePathMetaData(const Path & path, bool recurse)
|
void canonicalisePathMetaData(const Path & path, bool recurse)
|
||||||
{
|
{
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
|
@ -332,6 +315,8 @@ void LocalStore::registerValidPath(const ValidPathInfo & info, bool ignoreValidi
|
||||||
appendReferrer(*i, info.path, false);
|
appendReferrer(*i, info.path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(info.hash.type == htSHA256);
|
||||||
|
|
||||||
string s = (format(
|
string s = (format(
|
||||||
"Hash: sha256:%1%\n"
|
"Hash: sha256:%1%\n"
|
||||||
"References: %2%\n"
|
"References: %2%\n"
|
||||||
|
@ -676,10 +661,18 @@ Path LocalStore::addToStore(const Path & _srcPath,
|
||||||
Path srcPath(absPath(_srcPath));
|
Path srcPath(absPath(_srcPath));
|
||||||
debug(format("adding `%1%' to the store") % srcPath);
|
debug(format("adding `%1%' to the store") % srcPath);
|
||||||
|
|
||||||
std::pair<Path, Hash> pr =
|
/* Read the whole path into memory. This is not a very scalable
|
||||||
computeStorePathForPath(srcPath, recursive, hashAlgo, filter);
|
method for very large paths, but `copyPath' is mainly used for
|
||||||
Path & dstPath(pr.first);
|
small files. */
|
||||||
Hash & h(pr.second);
|
StringSink sink;
|
||||||
|
if (recursive)
|
||||||
|
dumpPath(srcPath, sink, filter);
|
||||||
|
else
|
||||||
|
sink.s = readFile(srcPath);
|
||||||
|
|
||||||
|
Hash h = hashString(parseHashType(hashAlgo), sink.s);
|
||||||
|
|
||||||
|
Path dstPath = makeFixedOutputPath(recursive, hashAlgo, h, baseNameOf(srcPath));
|
||||||
|
|
||||||
addTempRoot(dstPath);
|
addTempRoot(dstPath);
|
||||||
|
|
||||||
|
@ -694,19 +687,22 @@ Path LocalStore::addToStore(const Path & _srcPath,
|
||||||
|
|
||||||
if (pathExists(dstPath)) deletePathWrapped(dstPath);
|
if (pathExists(dstPath)) deletePathWrapped(dstPath);
|
||||||
|
|
||||||
copyPath(srcPath, dstPath, filter);
|
if (recursive) {
|
||||||
|
StringSource source(sink.s);
|
||||||
/* !!! */
|
restorePath(dstPath, source);
|
||||||
#if 0
|
} else
|
||||||
Hash h2 = hashPath(htSHA256, dstPath, filter);
|
writeStringToFile(dstPath, sink.s);
|
||||||
if (h != h2)
|
|
||||||
throw Error(format("contents of `%1%' changed while copying it to `%2%' (%3% -> %4%)")
|
|
||||||
% srcPath % dstPath % printHash(h) % printHash(h2));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
canonicalisePathMetaData(dstPath);
|
canonicalisePathMetaData(dstPath);
|
||||||
|
|
||||||
registerValidPath(dstPath, h, PathSet(), "");
|
/* Register the SHA-256 hash of the NAR serialisation of
|
||||||
|
the path in the database. We may just have computed it
|
||||||
|
above (if called with recursive == true and hashAlgo ==
|
||||||
|
sha256); otherwise, compute it here. */
|
||||||
|
registerValidPath(dstPath,
|
||||||
|
(recursive && hashAlgo == "sha256") ? h :
|
||||||
|
(recursive ? hashString(htSHA256, sink.s) : hashPath(htSHA256, dstPath)),
|
||||||
|
PathSet(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
outputLock.setDeletion(true);
|
outputLock.setDeletion(true);
|
||||||
|
|
Loading…
Reference in a new issue