aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/store-api.cc
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-04-28 00:56:10 +0200
committereldritch horrors <pennae@lix.systems>2024-05-09 23:18:05 +0200
commit28a98d152c071ec48b8bf510f87ac9710c56d7fb (patch)
treeb40d4a04510b36edf94c1d489a62683cf9db934a /src/libstore/store-api.cc
parent17965bf11c55daee81729151f9876e55fdeaf9c1 (diff)
libstore: de-callback-ify Store::queryRealisation
Change-Id: I8d74745c519518f163f51dfaa39063836f17599e
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r--src/libstore/store-api.cc73
1 files changed, 22 insertions, 51 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 7ebab3933..942e3f521 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -716,65 +716,36 @@ ref<const ValidPathInfo> Store::queryPathInfo(const StorePath & storePath)
return ref<const ValidPathInfo>(info);
}
-void Store::queryRealisation(const DrvOutput & id,
- Callback<std::shared_ptr<const Realisation>> callback) noexcept
+std::shared_ptr<const Realisation> Store::queryRealisation(const DrvOutput & id)
{
- try {
- if (diskCache) {
- auto [cacheOutcome, maybeCachedRealisation]
- = diskCache->lookupRealisation(getUri(), id);
- switch (cacheOutcome) {
- case NarInfoDiskCache::oValid:
- debug("Returning a cached realisation for %s", id.to_string());
- callback(maybeCachedRealisation);
- return;
- case NarInfoDiskCache::oInvalid:
- debug(
- "Returning a cached missing realisation for %s",
- id.to_string());
- callback(nullptr);
- return;
- case NarInfoDiskCache::oUnknown:
- break;
- }
+ if (diskCache) {
+ auto [cacheOutcome, maybeCachedRealisation]
+ = diskCache->lookupRealisation(getUri(), id);
+ switch (cacheOutcome) {
+ case NarInfoDiskCache::oValid:
+ debug("Returning a cached realisation for %s", id.to_string());
+ return maybeCachedRealisation;
+ case NarInfoDiskCache::oInvalid:
+ debug(
+ "Returning a cached missing realisation for %s",
+ id.to_string());
+ return nullptr;
+ case NarInfoDiskCache::oUnknown:
+ break;
}
- } catch (...) {
- return callback.rethrow();
}
- try {
- auto info = queryRealisationUncached(id);
+ auto info = queryRealisationUncached(id);
- if (diskCache) {
- if (info)
- diskCache->upsertRealisation(getUri(), *info);
- else
- diskCache->upsertAbsentRealisation(getUri(), id);
- }
-
- callback(std::shared_ptr<const Realisation>(info));
-
- } catch (...) {
- callback.rethrow();
+ if (diskCache) {
+ if (info)
+ diskCache->upsertRealisation(getUri(), *info);
+ else
+ diskCache->upsertAbsentRealisation(getUri(), id);
}
-}
-
-std::shared_ptr<const Realisation> Store::queryRealisation(const DrvOutput & id)
-{
- using RealPtr = std::shared_ptr<const Realisation>;
- std::promise<RealPtr> promise;
- queryRealisation(id,
- {[&](std::future<RealPtr> result) {
- try {
- promise.set_value(result.get());
- } catch (...) {
- promise.set_exception(std::current_exception());
- }
- }});
-
- return promise.get_future().get();
+ return info;
}
void Store::substitutePaths(const StorePathSet & paths)