diff options
author | Jade Lovelace <lix@jade.fyi> | 2024-09-11 00:27:39 -0700 |
---|---|---|
committer | Jade Lovelace <lix@jade.fyi> | 2024-09-13 17:11:43 -0700 |
commit | ca1dc3f70bf98e2424b7b2666ee2180675b67451 (patch) | |
tree | 95b6456887db362a627223dda55f22192f5832b0 /src/libstore/nar-accessor.cc | |
parent | 81c2e0ac8e76ddb3fd3c8e2ce59929853614b1b6 (diff) |
archive: refactor bad mutable-state API in the NAR parse listener
Remove the mutable state stuff that assumes that one file is being
written a time. It's true that we don't write multiple files
interleaved, but that mutable state is evil.
Change-Id: Ia1481da48255d901e4b09a9b783e7af44fae8cff
Diffstat (limited to 'src/libstore/nar-accessor.cc')
-rw-r--r-- | src/libstore/nar-accessor.cc | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/src/libstore/nar-accessor.cc b/src/libstore/nar-accessor.cc index fa7d5e3cb..7600de6e7 100644 --- a/src/libstore/nar-accessor.cc +++ b/src/libstore/nar-accessor.cc @@ -45,11 +45,12 @@ struct NarAccessor : public FSAccessor uint64_t pos = 0; + public: NarIndexer(NarAccessor & acc, Source & source) : acc(acc), source(source) { } - void createMember(const Path & path, NarMember member) + NarMember & createMember(const Path & path, NarMember member) { size_t level = std::count(path.begin(), path.end(), '/'); while (parents.size() > level) parents.pop(); @@ -63,6 +64,8 @@ struct NarAccessor : public FSAccessor auto result = parents.top()->children.emplace(baseNameOf(path), std::move(member)); parents.push(&result.first->second); } + + return *parents.top(); } void createDirectory(const Path & path) override @@ -70,28 +73,17 @@ struct NarAccessor : public FSAccessor createMember(path, {FSAccessor::Type::tDirectory, false, 0, 0}); } - void createRegularFile(const Path & path) override + std::unique_ptr<FileHandle> createRegularFile(const Path & path, uint64_t size, bool executable) override { - createMember(path, {FSAccessor::Type::tRegular, false, 0, 0}); - } - - void closeRegularFile() override - { } + auto & memb = createMember(path, {FSAccessor::Type::tRegular, false, 0, 0}); - void isExecutable() override - { - parents.top()->isExecutable = true; - } - - void preallocateContents(uint64_t size) override - { assert(size <= std::numeric_limits<uint64_t>::max()); - parents.top()->size = (uint64_t) size; - parents.top()->start = pos; - } + memb.size = (uint64_t) size; + memb.start = pos; + memb.isExecutable = executable; - void receiveContents(std::string_view data) override - { } + return std::make_unique<FileHandle>(); + } void createSymlink(const Path & path, const std::string & target) override { |