From e1caeb9680e5dcac74c3ef6fb75bcb66d41ea972 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Thu, 27 Feb 2025 16:08:50 +0100 Subject: [PATCH] libstore: extract source implementation from NarIndexer this is conflating concerns (position tracking in the input stream and actually unpacking its contents) in an unhelpful way and is preventing us removing full-path access requirements from the visitor concept. we want to move from reconstructing and then deconstructing paths to only passing individual entry names to nar parsers, who can then build full paths from the nar root only if the need those to function. not all of our implementations need this; only one of the three does, one ignores the paths entirely, and the third even takes the reconstruction apart. Change-Id: If249f13c5b9ae5b9e4e4a3777875ef8364ee6229 --- lix/libstore/nar-accessor.cc | 42 +++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/lix/libstore/nar-accessor.cc b/lix/libstore/nar-accessor.cc index 5f7c51e3b..fdf3ee2be 100644 --- a/lix/libstore/nar-accessor.cc +++ b/lix/libstore/nar-accessor.cc @@ -34,17 +34,30 @@ struct NarAccessor : public FSAccessor NarMember root; - struct NarIndexer : NARParseVisitor, Source + struct NarSource : Source + { + Source & source; + uint64_t pos = 0; + + NarSource(Source & source) : source(source) {} + + size_t read(char * data, size_t len) override + { + auto n = source.read(data, len); + pos += n; + return n; + } + }; + + struct NarIndexer : NARParseVisitor { NarAccessor & acc; - Source & source; + NarSource & source; std::stack parents; - uint64_t pos = 0; - public: - NarIndexer(NarAccessor & acc, Source & source) + NarIndexer(NarAccessor & acc, NarSource & source) : acc(acc), source(source) { } @@ -77,7 +90,7 @@ struct NarAccessor : public FSAccessor assert(size <= std::numeric_limits::max()); memb.size = (uint64_t) size; - memb.start = pos; + memb.start = source.pos; memb.isExecutable = executable; return std::make_unique(); @@ -88,26 +101,21 @@ struct NarAccessor : public FSAccessor createMember(path, NarMember{FSAccessor::Type::tSymlink, false, 0, 0, target}); } - - size_t read(char * data, size_t len) override - { - auto n = source.read(data, len); - pos += n; - return n; - } }; NarAccessor(std::string && _nar) : nar(_nar) { StringSource source(*nar); - NarIndexer indexer(*this, source); - parseDump(indexer, indexer); + NarSource posSource(source); + NarIndexer indexer(*this, posSource); + parseDump(indexer, posSource); } NarAccessor(Source & source) { - NarIndexer indexer(*this, source); - parseDump(indexer, indexer); + NarSource posSource(source); + NarIndexer indexer(*this, posSource); + parseDump(indexer, posSource); } NarAccessor(const std::string & listing, GetNarBytes getNarBytes)