From a2e523aa8b49e68b89b219d67637fbae6fda1d57 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 21 Feb 2025 00:35:11 +0100 Subject: [PATCH] libstore: asyncify BinaryCacheStore::addToStoreCommon Change-Id: I46710b11547515615f719e74501c1c8b4640ecc3 --- lix/libstore/binary-cache-store.cc | 24 +++++++++++++----------- lix/libstore/binary-cache-store.hh | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lix/libstore/binary-cache-store.cc b/lix/libstore/binary-cache-store.cc index c30be009f..63a274f27 100644 --- a/lix/libstore/binary-cache-store.cc +++ b/lix/libstore/binary-cache-store.cc @@ -99,10 +99,10 @@ void BinaryCacheStore::writeNarInfo(ref narInfo) diskCache->upsertNarInfo(getUri(), std::string(narInfo->path.hashPart()), std::shared_ptr(narInfo)); } -ref BinaryCacheStore::addToStoreCommon( +kj::Promise>> BinaryCacheStore::addToStoreCommon( Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs, std::function mkInfo) -{ +try { auto [fdTemp, fnTemp] = createTempFile(); AutoDelete autoDelete(fnTemp); @@ -253,7 +253,9 @@ ref BinaryCacheStore::addToStoreCommon( stats.narInfoWrite++; - return narInfo; + co_return narInfo; +} catch (...) { + co_return result::current_exception(); } kj::Promise> BinaryCacheStore::addToStore(const ValidPathInfo & info, Source & narSource, @@ -265,13 +267,13 @@ try { co_return result::success(); } - addToStoreCommon(narSource, repair, checkSigs, {[&](HashResult nar) { + TRY_AWAIT(addToStoreCommon(narSource, repair, checkSigs, {[&](HashResult nar) { /* FIXME reinstate these, once we can correctly do hash modulo sink as needed. We need to throw here in case we uploaded a corrupted store path. */ // assert(info.narHash == nar.first); // assert(info.narSize == nar.second); return info; - }}); + }})); co_return result::success(); } catch (...) { co_return result::current_exception(); @@ -282,7 +284,7 @@ kj::Promise> BinaryCacheStore::addToStoreFromDump(Source & dum try { if (method != FileIngestionMethod::Recursive || hashAlgo != HashType::SHA256) unsupported("addToStoreFromDump"); - co_return addToStoreCommon(dump, repair, CheckSigs, [&](HashResult nar) { + co_return TRY_AWAIT(addToStoreCommon(dump, repair, CheckSigs, [&](HashResult nar) { ValidPathInfo info { *this, name, @@ -299,7 +301,7 @@ try { }; info.narSize = nar.second; return info; - })->path; + }))->path; } catch (...) { co_return result::current_exception(); } @@ -393,7 +395,7 @@ try { auto h = sink.finish().first; auto source = GeneratorSource{dumpPath(srcPath, filter)}; - co_return addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) { + co_return TRY_AWAIT(addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) { ValidPathInfo info { *this, name, @@ -410,7 +412,7 @@ try { }; info.narSize = nar.second; return info; - })->path; + }))->path; } catch (...) { co_return result::current_exception(); } @@ -430,7 +432,7 @@ try { StringSink sink; sink << dumpString(s); StringSource source(sink.s); - co_return addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) { + co_return TRY_AWAIT(addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) { ValidPathInfo info { *this, std::string { name }, @@ -442,7 +444,7 @@ try { }; info.narSize = nar.second; return info; - })->path; + }))->path; } catch (...) { co_return result::current_exception(); } diff --git a/lix/libstore/binary-cache-store.hh b/lix/libstore/binary-cache-store.hh index 4ee11bc1f..e3ce627cb 100644 --- a/lix/libstore/binary-cache-store.hh +++ b/lix/libstore/binary-cache-store.hh @@ -101,7 +101,7 @@ private: void writeNarInfo(ref narInfo); - ref addToStoreCommon( + kj::Promise>> addToStoreCommon( Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs, std::function mkInfo);