Skip to content

Commit

Permalink
Fix makeContentAddressed() on self-references
Browse files Browse the repository at this point in the history
LocalStore::addToStore() since
79ae9e4 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.
  • Loading branch information
edolstra committed Mar 24, 2022
1 parent 545c2d0 commit f186075
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/libstore/make-content-addressed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());

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

0 comments on commit f186075

Please sign in to comment.