diff options
author | eldritch horrors <pennae@lix.systems> | 2024-05-01 20:10:00 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-07-06 12:36:37 +0200 |
commit | 5af76dee371ea5fa1eb72141370fdf18851d67c7 (patch) | |
tree | a51cc0348910a8fce0df02c132efe9a438ddd911 /src/libstore | |
parent | 4162a66cee97ec16c88d991ef9a6d9baa3740053 (diff) |
libutil: turn HashModuloSink into a free function
Change-Id: I5878007502fa68c2816a0f4c61f7d0e60bdde702
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/build/local-derivation-goal.cc | 18 | ||||
-rw-r--r-- | src/libstore/local-store.cc | 18 | ||||
-rw-r--r-- | src/libstore/make-content-addressed.cc | 8 |
3 files changed, 20 insertions, 24 deletions
diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc index b2a301b00..6a298e6eb 100644 --- a/src/libstore/build/local-derivation-goal.cc +++ b/src/libstore/build/local-derivation-goal.cc @@ -2216,23 +2216,21 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs() rewriteOutput(outputRewrites); /* FIXME optimize and deduplicate with addToStore */ std::string oldHashPart { scratchPath->hashPart() }; - HashModuloSink caSink { outputHash.hashType, oldHashPart }; - std::visit(overloaded { - [&](const TextIngestionMethod &) { - caSink << readFileSource(actualPath); + auto input = std::visit(overloaded { + [&](const TextIngestionMethod &) -> GeneratorSource { + return GeneratorSource(readFileSource(actualPath)); }, - [&](const FileIngestionMethod & m2) { + [&](const FileIngestionMethod & m2) -> GeneratorSource { switch (m2) { case FileIngestionMethod::Recursive: - caSink << dumpPath(actualPath); - break; + return GeneratorSource(dumpPath(actualPath)); case FileIngestionMethod::Flat: - caSink << readFileSource(actualPath); - break; + return GeneratorSource(readFileSource(actualPath)); } + assert(false); }, }, outputHash.method.raw); - auto got = caSink.finish().first; + auto got = computeHashModulo(outputHash.hashType, oldHashPart, input).first; auto optCA = ContentAddressWithReferences::fromPartsOpt( outputHash.method, diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 98e4d7efe..757aa21e3 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1887,25 +1887,23 @@ ContentAddress LocalStore::hashCAPath( const std::string_view pathHash ) { - HashModuloSink caSink ( hashType, std::string(pathHash) ); - std::visit(overloaded { - [&](const TextIngestionMethod &) { - caSink << readFileSource(path); + auto data = std::visit(overloaded { + [&](const TextIngestionMethod &) -> GeneratorSource { + return GeneratorSource(readFileSource(path)); }, - [&](const FileIngestionMethod & m2) { + [&](const FileIngestionMethod & m2) -> GeneratorSource { switch (m2) { case FileIngestionMethod::Recursive: - caSink << dumpPath(path); - break; + return GeneratorSource(dumpPath(path)); case FileIngestionMethod::Flat: - caSink << readFileSource(path); - break; + return GeneratorSource(readFileSource(path)); } + assert(false); }, }, method.raw); return ContentAddress { .method = method, - .hash = caSink.finish().first, + .hash = computeHashModulo(hashType, std::string(pathHash), data).first, }; } diff --git a/src/libstore/make-content-addressed.cc b/src/libstore/make-content-addressed.cc index 253609ed2..b5397541c 100644 --- a/src/libstore/make-content-addressed.cc +++ b/src/libstore/make-content-addressed.cc @@ -43,10 +43,10 @@ std::map<StorePath, StorePath> makeContentAddressed( sink.s = rewriteStrings(sink.s, rewrites); - HashModuloSink hashModuloSink(htSHA256, oldHashPart); - hashModuloSink(sink.s); - - auto narModuloHash = hashModuloSink.finish().first; + auto narModuloHash = [&] { + StringSource source{sink.s}; + return computeHashModulo(htSHA256, oldHashPart, source).first; + }(); ValidPathInfo info { dstStore, |