forked from lix-project/hydra
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 e92ac734e6
)
This commit is contained in:
parent
59f5a000f2
commit
413029892b
|
@ -7,8 +7,38 @@
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
struct Extractor : ParseSink
|
struct Extractor : NARParseVisitor
|
||||||
{
|
{
|
||||||
|
class MyFileHandle : public FileHandle
|
||||||
|
{
|
||||||
|
NarMemberData * memberData;
|
||||||
|
uint64_t expectedSize;
|
||||||
|
std::unique_ptr<HashSink> hashSink;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MyFileHandle(NarMemberData * memberData, uint64_t size) : memberData(memberData)
|
||||||
|
{
|
||||||
|
expectedSize = size;
|
||||||
|
hashSink = std::make_unique<HashSink>(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<Path> filesToKeep {
|
std::unordered_set<Path> filesToKeep {
|
||||||
"/nix-support/hydra-build-products",
|
"/nix-support/hydra-build-products",
|
||||||
"/nix-support/hydra-release-name",
|
"/nix-support/hydra-release-name",
|
||||||
|
@ -16,7 +46,6 @@ struct Extractor : ParseSink
|
||||||
};
|
};
|
||||||
|
|
||||||
NarMemberDatas & members;
|
NarMemberDatas & members;
|
||||||
NarMemberData * curMember = nullptr;
|
|
||||||
Path prefix;
|
Path prefix;
|
||||||
|
|
||||||
Extractor(NarMemberDatas & members, 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 });
|
members.insert_or_assign(prefix + path, NarMemberData { .type = FSAccessor::Type::tDirectory });
|
||||||
}
|
}
|
||||||
|
|
||||||
void createRegularFile(const Path & path) override
|
std::unique_ptr<FileHandle> 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,
|
.type = FSAccessor::Type::tRegular,
|
||||||
.fileSize = 0,
|
.fileSize = 0,
|
||||||
.contents = filesToKeep.count(path) ? std::optional("") : std::nullopt,
|
.contents = filesToKeep.count(path) ? std::optional("") : std::nullopt,
|
||||||
}).first->second;
|
}).first->second;
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<uint64_t> expectedSize;
|
return std::unique_ptr<MyFileHandle>(new MyFileHandle{memberData, size});
|
||||||
std::unique_ptr<HashSink> hashSink;
|
|
||||||
|
|
||||||
void preallocateContents(uint64_t size) override
|
|
||||||
{
|
|
||||||
expectedSize = size;
|
|
||||||
hashSink = std::make_unique<HashSink>(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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void createSymlink(const Path & path, const std::string & target) override
|
void createSymlink(const Path & path, const std::string & target) override
|
||||||
|
|
Loading…
Reference in a new issue