From 5af76dee371ea5fa1eb72141370fdf18851d67c7 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 1 May 2024 20:10:00 +0200 Subject: libutil: turn HashModuloSink into a free function Change-Id: I5878007502fa68c2816a0f4c61f7d0e60bdde702 --- src/libstore/build/local-derivation-goal.cc | 18 ++++++++---------- src/libstore/local-store.cc | 18 ++++++++---------- src/libstore/make-content-addressed.cc | 8 ++++---- 3 files changed, 20 insertions(+), 24 deletions(-) (limited to 'src/libstore') 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 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, -- cgit v1.2.3