libstore: asyncify BinaryCacheStore::getFileContents

Change-Id: I7972d6da6d0ac535d2d20c85390c6d67242cab35
This commit is contained in:
eldritch horrors
2025-06-15 13:36:31 +00:00
parent 743703ce35
commit 9f32ab85e8
2 changed files with 12 additions and 9 deletions
+10 -8
View File
@@ -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<Result<void>> 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::stringstream>(std::move(data)), mimeType);
}
std::optional<std::string> BinaryCacheStore::getFileContents(const std::string & path)
{
kj::Promise<Result<std::optional<std::string>>>
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();
}
+2 -1
View File
@@ -89,7 +89,8 @@ public:
*/
virtual box_ptr<Source> getFile(const std::string & path) = 0;
virtual std::optional<std::string> getFileContents(const std::string & path);
virtual kj::Promise<Result<std::optional<std::string>>> getFileContents(const std::string & path
);
public: