diff --git a/lix/libfetchers/path.cc b/lix/libfetchers/path.cc index a6d717528..e46f32ec1 100644 --- a/lix/libfetchers/path.cc +++ b/lix/libfetchers/path.cc @@ -133,7 +133,7 @@ struct PathInputScheme : InputScheme if (!storePath || storePath->name() != "source" || !store->isValidPath(*storePath)) { // FIXME: try to substitute storePath. auto src = GeneratorSource{dumpPathAndGetMtime(absPath, mtime, defaultPathFilter)}; - storePath = store->addToStoreFromDump(src, "source"); + storePath = TRY_AWAIT(store->addToStoreFromDump(src, "source")); } input.attrs.insert_or_assign("lastModified", uint64_t(mtime)); diff --git a/lix/libstore/binary-cache-store.cc b/lix/libstore/binary-cache-store.cc index ccdd28cd0..01385b2a4 100644 --- a/lix/libstore/binary-cache-store.cc +++ b/lix/libstore/binary-cache-store.cc @@ -277,12 +277,12 @@ try { co_return result::current_exception(); } -StorePath BinaryCacheStore::addToStoreFromDump(Source & dump, std::string_view name, +kj::Promise> BinaryCacheStore::addToStoreFromDump(Source & dump, std::string_view name, FileIngestionMethod method, HashType hashAlgo, RepairFlag repair, const StorePathSet & references) -{ +try { if (method != FileIngestionMethod::Recursive || hashAlgo != HashType::SHA256) unsupported("addToStoreFromDump"); - return addToStoreCommon(dump, repair, CheckSigs, [&](HashResult nar) { + co_return addToStoreCommon(dump, repair, CheckSigs, [&](HashResult nar) { ValidPathInfo info { *this, name, @@ -300,6 +300,8 @@ StorePath BinaryCacheStore::addToStoreFromDump(Source & dump, std::string_view n info.narSize = nar.second; return info; })->path; +} catch (...) { + co_return result::current_exception(); } bool BinaryCacheStore::isValidPathUncached(const StorePath & storePath) diff --git a/lix/libstore/binary-cache-store.hh b/lix/libstore/binary-cache-store.hh index 8381e24e1..daa923143 100644 --- a/lix/libstore/binary-cache-store.hh +++ b/lix/libstore/binary-cache-store.hh @@ -116,7 +116,7 @@ public: kj::Promise> addToStore(const ValidPathInfo & info, Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs) override; - StorePath addToStoreFromDump(Source & dump, std::string_view name, + kj::Promise> addToStoreFromDump(Source & dump, std::string_view name, FileIngestionMethod method, HashType hashAlgo, RepairFlag repair, const StorePathSet & references) override; kj::Promise> addToStore( diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index 964667ca7..3e08c102a 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -1080,17 +1080,19 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor return path; } - StorePath addToStoreFromDump( + kj::Promise> addToStoreFromDump( Source & dump, std::string_view name, FileIngestionMethod method, HashType hashAlgo, RepairFlag repair, const StorePathSet & references) override - { - auto path = next->addToStoreFromDump(dump, name, method, hashAlgo, repair, references); + try { + auto path = TRY_AWAIT(next->addToStoreFromDump(dump, name, method, hashAlgo, repair, references)); goal.addDependency(path); - return path; + co_return path; + } catch (...) { + co_return result::current_exception(); } box_ptr narFromPath(const StorePath & path) override diff --git a/lix/libstore/daemon.cc b/lix/libstore/daemon.cc index ef779a630..491d38550 100644 --- a/lix/libstore/daemon.cc +++ b/lix/libstore/daemon.cc @@ -427,7 +427,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref store return store->queryPathInfo(path); }, [&](const FileIngestionMethod & fim) { - auto path = store->addToStoreFromDump(source, name, fim, hashType, repair, refs); + auto path = aio.blockOn(store->addToStoreFromDump(source, name, fim, hashType, repair, refs)); return store->queryPathInfo(path); }, }, contentAddressMethod.raw); @@ -498,7 +498,7 @@ static void performOp(AsyncIoRoot & aio, TunnelLogger * logger, ref store }; GeneratorSource dumpSource{g()}; logger->startWork(); - auto path = store->addToStoreFromDump(dumpSource, baseName, method, hashAlgo); + auto path = aio.blockOn(store->addToStoreFromDump(dumpSource, baseName, method, hashAlgo)); logger->stopWork(); to << store->printStorePath(path); diff --git a/lix/libstore/local-store.cc b/lix/libstore/local-store.cc index 95f5f986a..919efbfc7 100644 --- a/lix/libstore/local-store.cc +++ b/lix/libstore/local-store.cc @@ -1281,9 +1281,9 @@ try { } -StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name, +kj::Promise> LocalStore::addToStoreFromDump(Source & source0, std::string_view name, FileIngestionMethod method, HashType hashAlgo, RepairFlag repair, const StorePathSet & references) -{ +try { /* For computing the store path. */ auto hashSink = std::make_unique(hashAlgo); TeeSource source { source0, *hashSink }; @@ -1419,7 +1419,9 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name } } - return dstPath; + co_return dstPath; +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/local-store.hh b/lix/libstore/local-store.hh index bab56600e..e3c185715 100644 --- a/lix/libstore/local-store.hh +++ b/lix/libstore/local-store.hh @@ -207,7 +207,7 @@ public: kj::Promise> addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs) override; - StorePath addToStoreFromDump(Source & dump, std::string_view name, + kj::Promise> addToStoreFromDump(Source & dump, std::string_view name, FileIngestionMethod method, HashType hashAlgo, RepairFlag repair, const StorePathSet & references) override; StorePath addTextToStore( diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index 057b13c58..4e6909762 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -458,10 +458,12 @@ ref RemoteStore::addCAToStore( } -StorePath RemoteStore::addToStoreFromDump(Source & dump, std::string_view name, +kj::Promise> RemoteStore::addToStoreFromDump(Source & dump, std::string_view name, FileIngestionMethod method, HashType hashType, RepairFlag repair, const StorePathSet & references) -{ - return addCAToStore(dump, name, method, hashType, references, repair)->path; +try { + co_return addCAToStore(dump, name, method, hashType, references, repair)->path; +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/remote-store.hh b/lix/libstore/remote-store.hh index 2faa29b11..af3fa82bb 100644 --- a/lix/libstore/remote-store.hh +++ b/lix/libstore/remote-store.hh @@ -85,7 +85,7 @@ public: /** * Add a content-addressable store path. Does not support references. `dump` will be drained. */ - StorePath addToStoreFromDump(Source & dump, std::string_view name, + kj::Promise> addToStoreFromDump(Source & dump, std::string_view name, FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = HashType::SHA256, RepairFlag repair = NoRepair, const StorePathSet & references = StorePathSet()) override; kj::Promise> addToStore(const ValidPathInfo & info, Source & nar, diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index b130ff26d..c36a94e8f 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -283,7 +283,7 @@ try { method == FileIngestionMethod::Recursive ? dumpPath(srcPath, filter).decay() : readFileSource(srcPath) }; - co_return addToStoreFromDump(source, name, method, hashAlgo, repair, references); + co_return TRY_AWAIT(addToStoreFromDump(source, name, method, hashAlgo, repair, references)); } catch (...) { co_return result::current_exception(); } diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index 5175d0de8..f5399c2d8 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -554,10 +554,10 @@ public: * * \todo remove? */ - virtual StorePath addToStoreFromDump(Source & dump, std::string_view name, + virtual kj::Promise> addToStoreFromDump(Source & dump, std::string_view name, FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = HashType::SHA256, RepairFlag repair = NoRepair, const StorePathSet & references = StorePathSet()) - { unsupported("addToStoreFromDump"); } + try { unsupported("addToStoreFromDump"); } catch (...) { return {result::current_exception()}; } /** * Like addToStore, but the contents written to the output path is a