From 9f32ab85e89b8b927cba705f2b7e00a0e27f0549 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 15 Jun 2025 14:47:08 +0200 Subject: [PATCH] libstore: asyncify BinaryCacheStore::getFileContents Change-Id: I7972d6da6d0ac535d2d20c85390c6d67242cab35 --- lix/libstore/binary-cache-store.cc | 18 ++++++++++-------- lix/libstore/binary-cache-store.hh | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lix/libstore/binary-cache-store.cc b/lix/libstore/binary-cache-store.cc index 632d13267..75b53f375 100644 --- a/lix/libstore/binary-cache-store.cc +++ b/lix/libstore/binary-cache-store.cc @@ -2,7 +2,6 @@ #include "lix/libstore/binary-cache-store.hh" #include "lix/libutil/async-io.hh" #include "lix/libutil/async.hh" -#include "lix/libutil/box_ptr.hh" #include "lix/libutil/compression.hh" #include "lix/libstore/derivations.hh" #include "lix/libstore/fs-accessor.hh" @@ -40,7 +39,7 @@ kj::Promise> BinaryCacheStore::init() try { std::string cacheInfoFile = "nix-cache-info"; - auto cacheInfo = getFileContents(cacheInfoFile); + auto cacheInfo = TRY_AWAIT(getFileContents(cacheInfoFile)); if (!cacheInfo) { upsertFile(cacheInfoFile, "StoreDir: " + config().storeDir + "\n", "text/x-nix-cache-info"); } else { @@ -72,13 +71,16 @@ void BinaryCacheStore::upsertFile(const std::string & path, upsertFile(path, std::make_shared(std::move(data)), mimeType); } -std::optional BinaryCacheStore::getFileContents(const std::string & path) -{ +kj::Promise>> +BinaryCacheStore::getFileContents(const std::string & path) +try { try { - return getFile(path)->drain(); + co_return getFile(path)->drain(); } catch (NoSuchBinaryCacheFile &) { - return std::nullopt; + co_return std::nullopt; } +} catch (...) { + co_return result::current_exception(); } std::string BinaryCacheStore::narInfoFileFor(const StorePath & storePath) @@ -425,7 +427,7 @@ try { auto narInfoFile = narInfoFileFor(storePath); - auto data = getFileContents(narInfoFile); + auto data = TRY_AWAIT(getFileContents(narInfoFile)); if (!data) co_return result::success(nullptr); @@ -566,7 +568,7 @@ try { debug("fetching build log from binary cache '%s/%s'", getUri(), logPath); - co_return getFileContents(logPath); + co_return TRY_AWAIT(getFileContents(logPath)); } catch (...) { co_return result::current_exception(); } diff --git a/lix/libstore/binary-cache-store.hh b/lix/libstore/binary-cache-store.hh index 054e624c1..4def85392 100644 --- a/lix/libstore/binary-cache-store.hh +++ b/lix/libstore/binary-cache-store.hh @@ -89,7 +89,8 @@ public: */ virtual box_ptr getFile(const std::string & path) = 0; - virtual std::optional getFileContents(const std::string & path); + virtual kj::Promise>> getFileContents(const std::string & path + ); public: