diff options
author | eldritch horrors <pennae@lix.systems> | 2024-04-27 19:55:54 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-05-09 23:18:05 +0200 |
commit | c77bd88259dac6e6b7bcb29425905467aa2ef66f (patch) | |
tree | 09d29a52225e9d8fe25c5fb9c66817c1c0a96745 /src/libstore/binary-cache-store.cc | |
parent | 1a002d1a11aed3ccf6f7271d82a3a07e61888cf9 (diff) |
libstore: de-callback-ify BinaryCacheStore::getFile
Change-Id: I36b3eb9f645aa04058151e7b2353e15e6f29057b
Diffstat (limited to 'src/libstore/binary-cache-store.cc')
-rw-r--r-- | src/libstore/binary-cache-store.cc | 71 |
1 files changed, 19 insertions, 52 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 502fac05f..bf7265c35 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -67,26 +67,9 @@ void BinaryCacheStore::upsertFile(const std::string & path, upsertFile(path, std::make_shared<std::stringstream>(std::move(data)), mimeType); } -void BinaryCacheStore::getFile(const std::string & path, - Callback<std::optional<std::string>> callback) noexcept -{ - try { - callback(getFile(path)); - } catch (...) { callback.rethrow(); } -} - void BinaryCacheStore::getFile(const std::string & path, Sink & sink) { - std::promise<std::optional<std::string>> promise; - getFile(path, - {[&](std::future<std::optional<std::string>> result) { - try { - promise.set_value(result.get()); - } catch (...) { - promise.set_exception(std::current_exception()); - } - }}); - sink(*promise.get_future().get()); + sink(*getFile(path)); } std::optional<std::string> BinaryCacheStore::getFile(const std::string & path) @@ -377,25 +360,17 @@ void BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath, auto narInfoFile = narInfoFileFor(storePath); - auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback)); - - getFile(narInfoFile, - {[=,this](std::future<std::optional<std::string>> fut) { - try { - auto data = fut.get(); - - if (!data) return (*callbackPtr)({}); + try { + auto data = getFile(narInfoFile); - stats.narInfoRead++; + if (!data) return callback({}); - (*callbackPtr)((std::shared_ptr<ValidPathInfo>) - std::make_shared<NarInfo>(*this, *data, narInfoFile)); + stats.narInfoRead++; - (void) act; // force Activity into this lambda to ensure it stays alive - } catch (...) { - callbackPtr->rethrow(); - } - }}); + callback(std::make_shared<NarInfo>(*this, *data, narInfoFile)); + } catch (...) { + callback.rethrow(); + } } StorePath BinaryCacheStore::addToStore( @@ -477,24 +452,16 @@ void BinaryCacheStore::queryRealisationUncached(const DrvOutput & id, { auto outputInfoFilePath = realisationsPrefix + "/" + id.to_string() + ".doi"; - auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback)); - - Callback<std::optional<std::string>> newCallback = { - [=](std::future<std::optional<std::string>> fut) { - try { - auto data = fut.get(); - if (!data) return (*callbackPtr)({}); - - auto realisation = Realisation::fromJSON( - nlohmann::json::parse(*data), outputInfoFilePath); - return (*callbackPtr)(std::make_shared<const Realisation>(realisation)); - } catch (...) { - callbackPtr->rethrow(); - } - } - }; - - getFile(outputInfoFilePath, std::move(newCallback)); + try { + auto data = getFile(outputInfoFilePath); + if (!data) return callback({}); + + auto realisation = Realisation::fromJSON( + nlohmann::json::parse(*data), outputInfoFilePath); + return callback(std::make_shared<const Realisation>(realisation)); + } catch (...) { + callback.rethrow(); + } } void BinaryCacheStore::registerDrvOutput(const Realisation& info) { |