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:
parent
8c4ea7a451
commit
7348653ff4
5 changed files with 36 additions and 17 deletions
|
@ -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();
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue