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
This commit is contained in:
eldritch horrors
2025-02-27 19:52:44 +00:00
parent c6a4cd6e3a
commit e1caeb9680
+25 -17
View File
@@ -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<NarMember *> 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<uint64_t>::max());
memb.size = (uint64_t) size;
memb.start = pos;
memb.start = source.pos;
memb.isExecutable = executable;
return std::make_unique<FileHandle>();
@@ -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)