diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-09-03T10·51+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-09-03T11·45+0200 |
commit | 7348653ff4fc4e9b2dc24943aabdb57179b1c75a (patch) | |
tree | c730713ccb743b185578ee1b37462a7fc68b10b4 /src/libstore/binary-cache-store.cc | |
parent | 8c4ea7a4516c517a0dd37b446bf5c1a6b157064c (diff) |
Ensure that Callback is called only once
Also, make Callback movable but uncopyable.
Diffstat (limited to 'src/libstore/binary-cache-store.cc')
-rw-r--r-- | src/libstore/binary-cache-store.cc | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 4527ee6ba660..e56be625de47 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -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(); } }}); } |