diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index 0d9cbaa63..1dcb1226f 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -530,13 +530,13 @@ try { sink << WorkerProto::Serialise::write(*this, WorkerProto::WriteConn {remoteVersion}, pathInfo); - pathSource->drainInto(sink); + pathSource()->drainInto(sink); } }); } else { for (auto & [pathInfo, pathSource] : pathsToCopy) { pathInfo.ultimate = false; // duplicated in daemon.cc AddMultipleToStore - TRY_AWAIT(addToStore(pathInfo, *pathSource, repair, checkSigs)); + TRY_AWAIT(addToStore(pathInfo, *pathSource(), repair, checkSigs)); } } co_return result::success(); diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index d4acafc5b..7a51d3611 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -4,7 +4,9 @@ #include "lix/libstore/store-api.hh" #include "lix/libstore/nar-info-disk-cache.hh" #include "lix/libutil/async.hh" +#include "lix/libutil/box_ptr.hh" #include "lix/libutil/result.hh" +#include "lix/libutil/serialise.hh" #include "lix/libutil/sync.hh" #include "lix/libutil/thread-pool.hh" #include "lix/libutil/url.hh" @@ -299,9 +301,7 @@ try { std::atomic bytesExpected{0}; std::atomic nrRunning{0}; - using PathWithInfo = std::pair>; - - std::map infosMap; + std::map infosMap; StorePathSet storePathsToAdd; for (auto & thingToAdd : pathsToCopy) { infosMap.insert_or_assign(thingToAdd.first.path, &thingToAdd); @@ -349,7 +349,7 @@ try { MaintainCount mc(nrRunning); showProgress(); try { - aio.blockOn(addToStore(info, *source, repair, checkSigs)); + aio.blockOn(addToStore(info, *source(), repair, checkSigs)); } catch (Error & e) { nrFailed++; if (!settings.keepGoing) @@ -1260,40 +1260,40 @@ try { ValidPathInfo infoForDst = *info; infoForDst.path = storePathForDst; - auto source = [](auto & srcStore, auto & dstStore, auto missingPath, auto info - ) -> WireFormatGenerator { - // We can reasonably assume that the copy will happen whenever we - // read the path, so log something about that at that point - auto srcUri = srcStore.getUri(); - auto dstUri = dstStore.getUri(); - auto storePathS = srcStore.printStorePath(missingPath); - Activity act( - *logger, - lvlInfo, - actCopyPath, - makeCopyPathMessage(srcUri, dstUri, storePathS), - {storePathS, srcUri, dstUri} - ); - PushActivity pact(act.id); + auto source = [&srcStore, &dstStore, missingPath, info] { + auto content = [](auto & srcStore, auto & dstStore, auto missingPath, auto info + ) -> WireFormatGenerator { + // We can reasonably assume that the copy will happen whenever we + // read the path, so log something about that at that point + auto srcUri = srcStore.getUri(); + auto dstUri = dstStore.getUri(); + auto storePathS = srcStore.printStorePath(missingPath); + Activity act( + *logger, + lvlInfo, + actCopyPath, + makeCopyPathMessage(srcUri, dstUri, storePathS), + {storePathS, srcUri, dstUri} + ); + PushActivity pact(act.id); - auto nar = srcStore.narFromPath(missingPath); - auto buf = std::make_unique(PATH_COPY_BUFSIZE); - uint64_t total = 0; - while (true) { - try { - auto got = nar->read(buf.get(), PATH_COPY_BUFSIZE); - total += got; - act.progress(total, info->narSize); - co_yield std::span{buf.get(), got}; - } catch (EndOfFile &) { - break; + auto nar = srcStore.narFromPath(missingPath); + auto buf = std::make_unique(PATH_COPY_BUFSIZE); + uint64_t total = 0; + while (true) { + try { + auto got = nar->read(buf.get(), PATH_COPY_BUFSIZE); + total += got; + act.progress(total, info->narSize); + co_yield std::span{buf.get(), got}; + } catch (EndOfFile &) { + break; + } } - } + }; + return make_box_ptr(content(srcStore, dstStore, missingPath, info)); }; - pathsToCopy.push_back(std::pair{ - infoForDst, - std::make_unique(source(srcStore, dstStore, missingPath, info)) - }); + pathsToCopy.push_back(std::pair{infoForDst, std::move(source)}); } TRY_AWAIT(dstStore.addMultipleToStore(pathsToCopy, act, repair, checkSigs)); diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index aca843101..5d75b4210 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -506,7 +506,7 @@ public: * A list of paths infos along with a source providing the content * of the associated store path */ - using PathsSource = std::vector>>; + using PathsSource = std::vector()>>>; /** * Import multiple paths into the store.