1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 15:51:15 +02:00

Ensure that Callback is called only once

Also, make Callback movable but uncopyable.
This commit is contained in:
Eelco Dolstra 2019-09-03 12:51:35 +02:00
parent 8c4ea7a451
commit 7348653ff4
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
5 changed files with 36 additions and 17 deletions

View file

@ -249,21 +249,23 @@ void BinaryCacheStore::queryPathInfoUncached(const Path & storePath,
auto narInfoFile = narInfoFileFor(storePath);
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
getFile(narInfoFile,
{[=](std::future<std::shared_ptr<std::string>> fut) {
try {
auto data = fut.get();
if (!data) return callback(nullptr);
if (!data) return (*callbackPtr)(nullptr);
stats.narInfoRead++;
callback((std::shared_ptr<ValidPathInfo>)
(*callbackPtr)((std::shared_ptr<ValidPathInfo>)
std::make_shared<NarInfo>(*this, *data, narInfoFile));
(void) act; // force Activity into this lambda to ensure it stays alive
} catch (...) {
callback.rethrow();
callbackPtr->rethrow();
}
}});
}