Normalize the hash-rewriting process when building derivations
This commit is contained in:
parent
a917fb0d53
commit
34e1b464f0
|
@ -2379,14 +2379,14 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
|
||||||
continue;
|
continue;
|
||||||
auto references = *referencesOpt;
|
auto references = *referencesOpt;
|
||||||
|
|
||||||
auto rewriteOutput = [&]() {
|
auto rewriteOutput = [&](const StringMap & rewrites) {
|
||||||
/* Apply hash rewriting if necessary. */
|
/* Apply hash rewriting if necessary. */
|
||||||
if (!outputRewrites.empty()) {
|
if (!rewrites.empty()) {
|
||||||
debug("rewriting hashes in '%1%'; cross fingers", actualPath);
|
debug("rewriting hashes in '%1%'; cross fingers", actualPath);
|
||||||
|
|
||||||
/* FIXME: Is this actually streaming? */
|
/* FIXME: Is this actually streaming? */
|
||||||
auto source = sinkToSource([&](Sink & nextSink) {
|
auto source = sinkToSource([&](Sink & nextSink) {
|
||||||
RewritingSink rsink(outputRewrites, nextSink);
|
RewritingSink rsink(rewrites, nextSink);
|
||||||
dumpPath(actualPath, rsink);
|
dumpPath(actualPath, rsink);
|
||||||
rsink.flush();
|
rsink.flush();
|
||||||
});
|
});
|
||||||
|
@ -2442,7 +2442,7 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
|
||||||
"since recursive hashing is not enabled (one of outputHashMode={flat,text} is true)",
|
"since recursive hashing is not enabled (one of outputHashMode={flat,text} is true)",
|
||||||
actualPath);
|
actualPath);
|
||||||
}
|
}
|
||||||
rewriteOutput();
|
rewriteOutput(outputRewrites);
|
||||||
/* FIXME optimize and deduplicate with addToStore */
|
/* FIXME optimize and deduplicate with addToStore */
|
||||||
std::string oldHashPart { scratchPath->hashPart() };
|
std::string oldHashPart { scratchPath->hashPart() };
|
||||||
HashModuloSink caSink { outputHash.hashType, oldHashPart };
|
HashModuloSink caSink { outputHash.hashType, oldHashPart };
|
||||||
|
@ -2480,16 +2480,14 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
|
||||||
Hash::dummy,
|
Hash::dummy,
|
||||||
};
|
};
|
||||||
if (*scratchPath != newInfo0.path) {
|
if (*scratchPath != newInfo0.path) {
|
||||||
// Also rewrite the output path
|
// If the path has some self-references, we need to rewrite
|
||||||
auto source = sinkToSource([&](Sink & nextSink) {
|
// them.
|
||||||
RewritingSink rsink2(oldHashPart, std::string(newInfo0.path.hashPart()), nextSink);
|
// (note that this doesn't invalidate the ca hash we calculated
|
||||||
dumpPath(actualPath, rsink2);
|
// above because it's computed *modulo the self-references*, so
|
||||||
rsink2.flush();
|
// it already takes this rewrite into account).
|
||||||
});
|
rewriteOutput(
|
||||||
Path tmpPath = actualPath + ".tmp";
|
StringMap{{oldHashPart,
|
||||||
restorePath(tmpPath, *source);
|
std::string(newInfo0.path.hashPart())}});
|
||||||
deletePath(actualPath);
|
|
||||||
movePath(tmpPath, actualPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HashResult narHashAndSize = hashPath(htSHA256, actualPath);
|
HashResult narHashAndSize = hashPath(htSHA256, actualPath);
|
||||||
|
@ -2511,7 +2509,7 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
|
||||||
outputRewrites.insert_or_assign(
|
outputRewrites.insert_or_assign(
|
||||||
std::string { scratchPath->hashPart() },
|
std::string { scratchPath->hashPart() },
|
||||||
std::string { requiredFinalPath.hashPart() });
|
std::string { requiredFinalPath.hashPart() });
|
||||||
rewriteOutput();
|
rewriteOutput(outputRewrites);
|
||||||
auto narHashAndSize = hashPath(htSHA256, actualPath);
|
auto narHashAndSize = hashPath(htSHA256, actualPath);
|
||||||
ValidPathInfo newInfo0 { requiredFinalPath, narHashAndSize.first };
|
ValidPathInfo newInfo0 { requiredFinalPath, narHashAndSize.first };
|
||||||
newInfo0.narSize = narHashAndSize.second;
|
newInfo0.narSize = narHashAndSize.second;
|
||||||
|
|
Loading…
Reference in a new issue