From 8fb3b89d0f6f37f0babc457437943d4e6d1e4d5c Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Thu, 16 May 2024 16:28:52 +0200 Subject: [PATCH] [WIP] libstore: remove a sinkToSouce from old daemon protocol this doesn't have a test because this code path is only reached by clients that predate 2.4, and we really should not be caring about those any more right now. even the test suite doesn't, and the few tests that might care are disabled because they will not even work Change-Id: Id9eb190065138fedb2c7d90c328ff9eb9d97385b --- src/libstore/daemon.cc | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index f7b6a38a1..2aa5bde07 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -453,7 +453,7 @@ static void performOp(TunnelLogger * logger, ref store, hashAlgo = parseHashType(hashAlgoRaw); } - auto dumpSource = sinkToSource([&](Sink & saved) { + GeneratorSource dumpSource{[&]() -> WireFormatGenerator { if (method == FileIngestionMethod::Recursive) { /* We parse the NAR dump through into `saved` unmodified, so why all this extra work? We still parse the NAR so @@ -463,18 +463,33 @@ static void performOp(TunnelLogger * logger, ref store, command. (We don't trust `addToStoreFromDump` to not eagerly consume the entire stream it's given, past the length of the Nar. */ - saved << copyNAR(from); + co_yield copyNAR(from); } else { /* Incrementally parse the NAR file, stripping the metadata, and streaming the sole file we expect into `saved`. */ - RetrieveRegularNARSink savedRegular { saved }; - parseDump(savedRegular, from); - if (!savedRegular.regular) throw Error("regular file expected"); + auto parser = nar::parse(from); + nar::File * file = nullptr; + while (auto entry = parser.next()) { + file = std::visit( + overloaded{ + [](nar::MetadataString) -> nar::File * { return nullptr; }, + [](nar::MetadataRaw) -> nar::File * { return nullptr; }, + [](nar::File & f) -> nar::File * { return &f; }, + [](auto &) -> nar::File * { throw Error("regular file expected"); }, + }, + *entry + ); + if (file) { + break; + } + } + assert(file); // should never fail unless the nar is empty, which would be invalid + co_yield std::move(file->contents); } - }); + }()}; logger->startWork(); - auto path = store->addToStoreFromDump(*dumpSource, baseName, method, hashAlgo); + auto path = store->addToStoreFromDump(dumpSource, baseName, method, hashAlgo); logger->stopWork(); to << store->printStorePath(path);