From 45be1e8d668a56c2e2c9b9d6ec47e40d4c97f165 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Thu, 27 Feb 2025 16:08:50 +0100 Subject: [PATCH] libutil: implement copyNAR with parse + dump Change-Id: I2bf6a0dc052d2f4012cc8fe3ced4c8cefd6572e5 --- lix/libutil/archive.cc | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/lix/libutil/archive.cc b/lix/libutil/archive.cc index 02e9a95f3..b2dcfd058 100644 --- a/lix/libutil/archive.cc +++ b/lix/libutil/archive.cc @@ -551,30 +551,18 @@ WireFormatGenerator copyNAR(Source & source) // FIXME: if 'source' is the output of dumpPath() followed by EOF, // we should just forward all data directly without parsing. - struct DiscardVisitor : NARParseVisitor - { - struct MyFileHandle : FileHandle - { - void close() override {} - void receiveContents(std::string_view data) override {} - }; - - box_ptr createDirectory(const Path & path) override - { - return make_box_ptr(); - } - - box_ptr createRegularFile(const Path & path, uint64_t size, bool executable) override - { - return make_box_ptr(); - } - - void createSymlink(const Path & path, const std::string & target) override {} - }; - - static DiscardVisitor parseSink; /* null sink; just parse the NAR */ - - return parseAndCopyDump(parseSink, source); + auto items = nar::parse(source); + co_yield narVersionMagic1; + while (auto e = items.next()) { + co_yield std::visit( + overloaded{ + [](nar::MetadataString &) -> WireFormatGenerator { co_return; }, + [](nar::MetadataRaw &) -> WireFormatGenerator { co_return; }, + [](auto & i) { return dump(std::move(i)); }, + }, + *e + ); + } } }