aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/make-content-addressed.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2022-03-22 21:47:50 +0100
committerEelco Dolstra <edolstra@gmail.com>2022-03-24 21:33:33 +0100
commitf18607549ce38545b1d754ed93f3b7c5417970d8 (patch)
tree22c8dbe103a983dfffe9a3b99d027861bab4d66b /src/libstore/make-content-addressed.cc
parent545c2d0d8cbac86c169a6dd049c1ed9c3913774d (diff)
Fix makeContentAddressed() on self-references
LocalStore::addToStore() since 79ae9e4558cbefd743f28a5e73110c2303b03a85 expects a regular NAR hash, rather than a NAR hash modulo self-references. Fixes #6300. Also, makeContentAddressed() now rewrites the entire closure (so 'nix store make-content-addressable' no longer needs '-r'). See #6301.
Diffstat (limited to 'src/libstore/make-content-addressed.cc')
-rw-r--r--src/libstore/make-content-addressed.cc35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/libstore/make-content-addressed.cc b/src/libstore/make-content-addressed.cc
index 0b95ff37c..fc11fcb27 100644
--- a/src/libstore/make-content-addressed.cc
+++ b/src/libstore/make-content-addressed.cc
@@ -8,9 +8,10 @@ std::map<StorePath, StorePath> makeContentAddressed(
Store & dstStore,
const StorePathSet & storePaths)
{
- // FIXME: use closure of storePaths.
+ StorePathSet closure;
+ srcStore.computeFSClosure(storePaths, closure);
- auto paths = srcStore.topoSortPaths(storePaths);
+ auto paths = srcStore.topoSortPaths(closure);
std::reverse(paths.begin(), paths.end());
@@ -46,29 +47,29 @@ std::map<StorePath, StorePath> makeContentAddressed(
HashModuloSink hashModuloSink(htSHA256, oldHashPart);
hashModuloSink(sink.s);
- auto narHash = hashModuloSink.finish().first;
+ auto narModuloHash = hashModuloSink.finish().first;
- ValidPathInfo info {
- dstStore.makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, path.name(), references, hasSelfReference),
- narHash,
- };
+ auto dstPath = dstStore.makeFixedOutputPath(
+ FileIngestionMethod::Recursive, narModuloHash, path.name(), references, hasSelfReference);
+
+ printInfo("rewroting '%s' to '%s'", pathS, srcStore.printStorePath(dstPath));
+
+ StringSink sink2;
+ RewritingSink rsink2(oldHashPart, std::string(dstPath.hashPart()), sink2);
+ rsink2(sink.s);
+ rsink2.flush();
+
+ ValidPathInfo info { dstPath, hashString(htSHA256, sink2.s) };
info.references = std::move(references);
if (hasSelfReference) info.references.insert(info.path);
info.narSize = sink.s.size();
info.ca = FixedOutputHash {
.method = FileIngestionMethod::Recursive,
- .hash = info.narHash,
+ .hash = narModuloHash,
};
- printInfo("rewrote '%s' to '%s'", pathS, srcStore.printStorePath(info.path));
-
- auto source = sinkToSource([&](Sink & nextSink) {
- RewritingSink rsink2(oldHashPart, std::string(info.path.hashPart()), nextSink);
- rsink2(sink.s);
- rsink2.flush();
- });
-
- dstStore.addToStore(info, *source);
+ StringSource source(sink2.s);
+ dstStore.addToStore(info, source);
remappings.insert_or_assign(std::move(path), std::move(info.path));
}