forked from lix-project/hydra
hydra-queue-runner/nar-extractor: address review comments
* Turn `NarMemberData` in `MyFileHandle` into a reference. * `expectedSize` now uses an initializer. * Used `std::make_unique` instead of `std::unique_ptr(new ...)` as suggested by clangd.
This commit is contained in:
parent
e92ac734e6
commit
06a30ec8df
|
@ -11,29 +11,28 @@ struct Extractor : NARParseVisitor
|
||||||
{
|
{
|
||||||
class MyFileHandle : public FileHandle
|
class MyFileHandle : public FileHandle
|
||||||
{
|
{
|
||||||
NarMemberData * memberData;
|
NarMemberData & memberData;
|
||||||
uint64_t expectedSize;
|
uint64_t expectedSize;
|
||||||
std::unique_ptr<HashSink> hashSink;
|
std::unique_ptr<HashSink> hashSink;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyFileHandle(NarMemberData * memberData, uint64_t size) : memberData(memberData)
|
MyFileHandle(NarMemberData & memberData, uint64_t size) : memberData(memberData), expectedSize(size)
|
||||||
{
|
{
|
||||||
expectedSize = size;
|
|
||||||
hashSink = std::make_unique<HashSink>(HashType::SHA256);
|
hashSink = std::make_unique<HashSink>(HashType::SHA256);
|
||||||
}
|
}
|
||||||
|
|
||||||
void receiveContents(std::string_view data) override
|
void receiveContents(std::string_view data) override
|
||||||
{
|
{
|
||||||
*memberData->fileSize += data.size();
|
*memberData.fileSize += data.size();
|
||||||
(*hashSink)(data);
|
(*hashSink)(data);
|
||||||
if (memberData->contents) {
|
if (memberData.contents) {
|
||||||
memberData->contents->append(data);
|
memberData.contents->append(data);
|
||||||
}
|
}
|
||||||
assert(memberData->fileSize <= expectedSize);
|
assert(memberData.fileSize <= expectedSize);
|
||||||
if (memberData->fileSize == expectedSize) {
|
if (memberData.fileSize == expectedSize) {
|
||||||
auto [hash, len] = hashSink->finish();
|
auto [hash, len] = hashSink->finish();
|
||||||
assert(memberData->fileSize == len);
|
assert(memberData.fileSize == len);
|
||||||
memberData->sha256 = hash;
|
memberData.sha256 = hash;
|
||||||
hashSink.reset();
|
hashSink.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +64,7 @@ struct Extractor : NARParseVisitor
|
||||||
.contents = filesToKeep.count(path) ? std::optional("") : std::nullopt,
|
.contents = filesToKeep.count(path) ? std::optional("") : std::nullopt,
|
||||||
}).first->second;
|
}).first->second;
|
||||||
|
|
||||||
return std::unique_ptr<MyFileHandle>(new MyFileHandle{memberData, size});
|
return std::make_unique<MyFileHandle>(*memberData, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
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