forked from lix-project/lix
Merge pull request #4849 from NixOS/ca/fix-nix-store--export
Make the Nar hash non modulo
This commit is contained in:
commit
b10256af51
|
@ -2354,32 +2354,19 @@ void LocalDerivationGoal::registerOutputs()
|
||||||
}
|
}
|
||||||
auto got = caSink.finish().first;
|
auto got = caSink.finish().first;
|
||||||
auto refs = rewriteRefs();
|
auto refs = rewriteRefs();
|
||||||
HashModuloSink narSink { htSHA256, oldHashPart };
|
|
||||||
dumpPath(actualPath, narSink);
|
auto finalPath = worker.store.makeFixedOutputPath(
|
||||||
auto narHashAndSize = narSink.finish();
|
|
||||||
ValidPathInfo newInfo0 {
|
|
||||||
worker.store.makeFixedOutputPath(
|
|
||||||
outputHash.method,
|
outputHash.method,
|
||||||
got,
|
got,
|
||||||
outputPathName(drv->name, outputName),
|
outputPathName(drv->name, outputName),
|
||||||
refs.second,
|
refs.second,
|
||||||
refs.first),
|
refs.first);
|
||||||
narHashAndSize.first,
|
if (scratchPath != finalPath) {
|
||||||
};
|
|
||||||
newInfo0.narSize = narHashAndSize.second;
|
|
||||||
newInfo0.ca = FixedOutputHash {
|
|
||||||
.method = outputHash.method,
|
|
||||||
.hash = got,
|
|
||||||
};
|
|
||||||
newInfo0.references = refs.second;
|
|
||||||
if (refs.first)
|
|
||||||
newInfo0.references.insert(newInfo0.path);
|
|
||||||
if (scratchPath != newInfo0.path) {
|
|
||||||
// Also rewrite the output path
|
// Also rewrite the output path
|
||||||
auto source = sinkToSource([&](Sink & nextSink) {
|
auto source = sinkToSource([&](Sink & nextSink) {
|
||||||
StringSink sink;
|
StringSink sink;
|
||||||
dumpPath(actualPath, sink);
|
dumpPath(actualPath, sink);
|
||||||
RewritingSink rsink2(oldHashPart, std::string(newInfo0.path.hashPart()), nextSink);
|
RewritingSink rsink2(oldHashPart, std::string(finalPath.hashPart()), nextSink);
|
||||||
rsink2(*sink.s);
|
rsink2(*sink.s);
|
||||||
rsink2.flush();
|
rsink2.flush();
|
||||||
});
|
});
|
||||||
|
@ -2389,6 +2376,21 @@ void LocalDerivationGoal::registerOutputs()
|
||||||
movePath(tmpPath, actualPath);
|
movePath(tmpPath, actualPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HashResult narHashAndSize = hashPath(htSHA256, actualPath);
|
||||||
|
ValidPathInfo newInfo0 {
|
||||||
|
finalPath,
|
||||||
|
narHashAndSize.first,
|
||||||
|
};
|
||||||
|
|
||||||
|
newInfo0.narSize = narHashAndSize.second;
|
||||||
|
newInfo0.ca = FixedOutputHash {
|
||||||
|
.method = outputHash.method,
|
||||||
|
.hash = got,
|
||||||
|
};
|
||||||
|
newInfo0.references = refs.second;
|
||||||
|
if (refs.first)
|
||||||
|
newInfo0.references.insert(newInfo0.path);
|
||||||
|
|
||||||
assert(newInfo0.ca);
|
assert(newInfo0.ca);
|
||||||
return newInfo0;
|
return newInfo0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1152,17 +1152,13 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
|
||||||
|
|
||||||
/* While restoring the path from the NAR, compute the hash
|
/* While restoring the path from the NAR, compute the hash
|
||||||
of the NAR. */
|
of the NAR. */
|
||||||
std::unique_ptr<AbstractHashSink> hashSink;
|
HashSink hashSink(htSHA256);
|
||||||
if (!info.ca.has_value() || !info.references.count(info.path))
|
|
||||||
hashSink = std::make_unique<HashSink>(htSHA256);
|
|
||||||
else
|
|
||||||
hashSink = std::make_unique<HashModuloSink>(htSHA256, std::string(info.path.hashPart()));
|
|
||||||
|
|
||||||
TeeSource wrapperSource { source, *hashSink };
|
TeeSource wrapperSource { source, hashSink };
|
||||||
|
|
||||||
restorePath(realPath, wrapperSource);
|
restorePath(realPath, wrapperSource);
|
||||||
|
|
||||||
auto hashResult = hashSink->finish();
|
auto hashResult = hashSink.finish();
|
||||||
|
|
||||||
if (hashResult.first != info.narHash)
|
if (hashResult.first != info.narHash)
|
||||||
throw Error("hash mismatch importing path '%s';\n specified: %s\n got: %s",
|
throw Error("hash mismatch importing path '%s';\n specified: %s\n got: %s",
|
||||||
|
@ -1440,14 +1436,10 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
|
||||||
/* Check the content hash (optionally - slow). */
|
/* Check the content hash (optionally - slow). */
|
||||||
printMsg(lvlTalkative, "checking contents of '%s'", printStorePath(i));
|
printMsg(lvlTalkative, "checking contents of '%s'", printStorePath(i));
|
||||||
|
|
||||||
std::unique_ptr<AbstractHashSink> hashSink;
|
auto hashSink = HashSink(info->narHash.type);
|
||||||
if (!info->ca || !info->references.count(info->path))
|
|
||||||
hashSink = std::make_unique<HashSink>(info->narHash.type);
|
|
||||||
else
|
|
||||||
hashSink = std::make_unique<HashModuloSink>(info->narHash.type, std::string(info->path.hashPart()));
|
|
||||||
|
|
||||||
dumpPath(Store::toRealPath(i), *hashSink);
|
dumpPath(Store::toRealPath(i), hashSink);
|
||||||
auto current = hashSink->finish();
|
auto current = hashSink.finish();
|
||||||
|
|
||||||
if (info->narHash != nullHash && info->narHash != current.first) {
|
if (info->narHash != nullHash && info->narHash != current.first) {
|
||||||
printError("path '%s' was modified! expected hash '%s', got '%s'",
|
printError("path '%s' was modified! expected hash '%s', got '%s'",
|
||||||
|
|
|
@ -97,15 +97,11 @@ struct CmdVerify : StorePathsCommand
|
||||||
|
|
||||||
if (!noContents) {
|
if (!noContents) {
|
||||||
|
|
||||||
std::unique_ptr<AbstractHashSink> hashSink;
|
auto hashSink = HashSink(info->narHash.type);
|
||||||
if (!info->ca)
|
|
||||||
hashSink = std::make_unique<HashSink>(info->narHash.type);
|
|
||||||
else
|
|
||||||
hashSink = std::make_unique<HashModuloSink>(info->narHash.type, std::string(info->path.hashPart()));
|
|
||||||
|
|
||||||
store->narFromPath(info->path, *hashSink);
|
store->narFromPath(info->path, hashSink);
|
||||||
|
|
||||||
auto hash = hashSink->finish();
|
auto hash = hashSink.finish();
|
||||||
|
|
||||||
if (hash.first != info->narHash) {
|
if (hash.first != info->narHash) {
|
||||||
corrupted++;
|
corrupted++;
|
||||||
|
|
Loading…
Reference in a new issue