From f43dbf3035b0bed638b3280246b284710fdc945f Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 4 Mar 2025 23:08:34 +0100 Subject: [PATCH] libstore: asyncify Derivation::checkInvariants Change-Id: I269d5d11af811e4ab2f099fdc4e1c56597f38678 --- lix/libstore/derivations.cc | 8 ++++++-- lix/libstore/derivations.hh | 2 +- lix/libstore/local-store.cc | 4 ++-- lix/nix/derivation-add.cc | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lix/libstore/derivations.cc b/lix/libstore/derivations.cc index 465bb9a0a..3cff272af 100644 --- a/lix/libstore/derivations.cc +++ b/lix/libstore/derivations.cc @@ -1161,8 +1161,9 @@ try { } -void Derivation::checkInvariants(Store & store, const StorePath & drvPath) const -{ +kj::Promise> +Derivation::checkInvariants(Store & store, const StorePath & drvPath) const +try { assert(drvPath.isDerivation()); std::string drvName(drvPath.name()); drvName = drvName.substr(0, drvName.size() - drvExtension.size()); @@ -1218,6 +1219,9 @@ void Derivation::checkInvariants(Store & store, const StorePath & drvPath) const }, }, i.second.raw); } + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/derivations.hh b/lix/libstore/derivations.hh index cdf9a5857..8216fd2ca 100644 --- a/lix/libstore/derivations.hh +++ b/lix/libstore/derivations.hh @@ -362,7 +362,7 @@ struct Derivation : BasicDerivation * representation supports all sorts of combinations we do not yet * allow. */ - void checkInvariants(Store & store, const StorePath & drvPath) const; + kj::Promise> checkInvariants(Store & store, const StorePath & drvPath) const; Derivation() = default; Derivation(const BasicDerivation & bd) : BasicDerivation(bd) { } diff --git a/lix/libstore/local-store.cc b/lix/libstore/local-store.cc index 53dcca1f1..07eaa295b 100644 --- a/lix/libstore/local-store.cc +++ b/lix/libstore/local-store.cc @@ -894,7 +894,7 @@ try { derivations). Note that if this throws an error, then the DB transaction is rolled back, so the path validity registration above is undone. */ - if (checkOutputs) drv.checkInvariants(*this, info.path); + if (checkOutputs) TRY_AWAIT(drv.checkInvariants(*this, info.path)); for (auto & i : drv.outputsAndOptPaths(*this)) { /* Floating CA derivations have indeterminate output paths until @@ -1228,7 +1228,7 @@ try { for (auto & [_, i] : infos) if (i.path.isDerivation()) { // FIXME: inefficient; we already loaded the derivation in addValidPath(). - readInvalidDerivation(i.path).checkInvariants(*this, i.path); + TRY_AWAIT(readInvalidDerivation(i.path).checkInvariants(*this, i.path)); } /* Do a topological sort of the paths. This will throw an diff --git a/lix/nix/derivation-add.cc b/lix/nix/derivation-add.cc index 965ce1f08..819d6ec63 100644 --- a/lix/nix/derivation-add.cc +++ b/lix/nix/derivation-add.cc @@ -34,7 +34,7 @@ struct CmdAddDerivation : MixDryRun, StoreCommand auto drvPath = aio().blockOn(writeDerivation(*store, drv, NoRepair, /* read only */ dryRun)); - drv.checkInvariants(*store, drvPath); + aio().blockOn(drv.checkInvariants(*store, drvPath)); aio().blockOn(writeDerivation(*store, drv, NoRepair, dryRun));