From 413029892b20d8a273b605a96240eb1812271583 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Thu, 26 Sep 2024 09:31:43 +0200 Subject: [PATCH] Fix build with latest Lix Since ca1dc3f70bf98e2424b7b2666ee2180675b67451, the NAR parser has moved the preallocate & receive steps into the file handle class to remove the assumption that only one file can be handled at a time. (cherry picked from commit e92ac734e619a6e92747a05e6440c98c06a6e27d) --- .envrc | 2 +- src/hydra-queue-runner/nar-extractor.cc | 65 +++++++++++++------------ 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/.envrc b/.envrc index 3550a30f..4359d1f6 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use flake +use flake .#clang diff --git a/src/hydra-queue-runner/nar-extractor.cc b/src/hydra-queue-runner/nar-extractor.cc index b3350193..31c0db65 100644 --- a/src/hydra-queue-runner/nar-extractor.cc +++ b/src/hydra-queue-runner/nar-extractor.cc @@ -7,8 +7,38 @@ using namespace nix; -struct Extractor : ParseSink +struct Extractor : NARParseVisitor { + class MyFileHandle : public FileHandle + { + NarMemberData * memberData; + uint64_t expectedSize; + std::unique_ptr hashSink; + + public: + MyFileHandle(NarMemberData * memberData, uint64_t size) : memberData(memberData) + { + expectedSize = size; + hashSink = std::make_unique(HashType::SHA256); + } + + void receiveContents(std::string_view data) override + { + *memberData->fileSize += data.size(); + (*hashSink)(data); + if (memberData->contents) { + memberData->contents->append(data); + } + assert(memberData->fileSize <= expectedSize); + if (memberData->fileSize == expectedSize) { + auto [hash, len] = hashSink->finish(); + assert(memberData->fileSize == len); + memberData->sha256 = hash; + hashSink.reset(); + } + } + }; + std::unordered_set filesToKeep { "/nix-support/hydra-build-products", "/nix-support/hydra-release-name", @@ -16,7 +46,6 @@ struct Extractor : ParseSink }; NarMemberDatas & members; - NarMemberData * curMember = nullptr; Path prefix; Extractor(NarMemberDatas & members, Path prefix) @@ -28,41 +57,15 @@ struct Extractor : ParseSink members.insert_or_assign(prefix + path, NarMemberData { .type = FSAccessor::Type::tDirectory }); } - void createRegularFile(const Path & path) override + std::unique_ptr createRegularFile(const Path & path, uint64_t size, bool executable) override { - curMember = &members.insert_or_assign(prefix + path, NarMemberData { + auto memberData = &members.insert_or_assign(prefix + path, NarMemberData { .type = FSAccessor::Type::tRegular, .fileSize = 0, .contents = filesToKeep.count(path) ? std::optional("") : std::nullopt, }).first->second; - } - std::optional expectedSize; - std::unique_ptr hashSink; - - void preallocateContents(uint64_t size) override - { - expectedSize = size; - hashSink = std::make_unique(HashType::SHA256); - } - - void receiveContents(std::string_view data) override - { - assert(expectedSize); - assert(curMember); - assert(hashSink); - *curMember->fileSize += data.size(); - (*hashSink)(data); - if (curMember->contents) { - curMember->contents->append(data); - } - assert(curMember->fileSize <= expectedSize); - if (curMember->fileSize == expectedSize) { - auto [hash, len] = hashSink->finish(); - assert(curMember->fileSize == len); - curMember->sha256 = hash; - hashSink.reset(); - } + return std::unique_ptr(new MyFileHandle{memberData, size}); } void createSymlink(const Path & path, const std::string & target) override