From cc3a9897e3a0e22b8fe2007cbaae9503d641a898 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 21 Feb 2025 00:35:11 +0100 Subject: [PATCH] libstore: asyncify printClosureDiff Change-Id: I4982d34e565f9e59931c4e675c2d142fcacce81f --- lix/libcmd/command.hh | 2 +- lix/nix/diff-closures.cc | 23 +++++++++++++++-------- lix/nix/profile.cc | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lix/libcmd/command.hh b/lix/libcmd/command.hh index 055c4a451..3604118b9 100644 --- a/lix/libcmd/command.hh +++ b/lix/libcmd/command.hh @@ -371,7 +371,7 @@ void completeFlakeRefWithFragment( const Strings & defaultFlakeAttrPaths, std::string_view prefix); -void printClosureDiff( +kj::Promise> printClosureDiff( ref store, const StorePath & beforePath, const StorePath & afterPath, diff --git a/lix/nix/diff-closures.cc b/lix/nix/diff-closures.cc index 4ee9c554a..e9a371b1d 100644 --- a/lix/nix/diff-closures.cc +++ b/lix/nix/diff-closures.cc @@ -4,6 +4,7 @@ #include "lix/libstore/store-api.hh" #include "lix/libmain/common-args.hh" #include "lix/libstore/names.hh" +#include "lix/libutil/result.hh" #include @@ -17,8 +18,9 @@ struct Info // name -> version -> store paths typedef std::map>> GroupedPaths; -GroupedPaths getClosureInfo(ref store, const StorePath & toplevel) -{ +static kj::Promise> +getClosureInfo(ref store, const StorePath & toplevel) +try { StorePathSet closure; store->computeFSClosure({toplevel}, closure); @@ -43,17 +45,19 @@ GroupedPaths getClosureInfo(ref store, const StorePath & toplevel) groupedPaths[drvName.name][drvName.version].emplace(path, Info { .outputName = outputName }); } - return groupedPaths; + co_return groupedPaths; +} catch (...) { + co_return result::current_exception(); } -void printClosureDiff( +kj::Promise> printClosureDiff( ref store, const StorePath & beforePath, const StorePath & afterPath, std::string_view indent) -{ - auto beforeClosure = getClosureInfo(store, beforePath); - auto afterClosure = getClosureInfo(store, afterPath); +try { + auto beforeClosure = TRY_AWAIT(getClosureInfo(store, beforePath)); + auto afterClosure = TRY_AWAIT(getClosureInfo(store, afterPath)); std::set allNames; for (auto & [name, _] : beforeClosure) allNames.insert(name); @@ -94,6 +98,9 @@ void printClosureDiff( logger->cout("%s%s: %s", indent, name, concatStringsSep(", ", items)); } } + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } } @@ -129,7 +136,7 @@ struct CmdDiffClosures : SourceExprCommand, MixOperateOnOptions auto beforePath = Installable::toStorePath(*state, getEvalStore(), store, Realise::Outputs, operateOn, before); auto after = parseInstallable(*state, store, _after); auto afterPath = Installable::toStorePath(*state, getEvalStore(), store, Realise::Outputs, operateOn, after); - printClosureDiff(store, beforePath, afterPath, ""); + aio().blockOn(printClosureDiff(store, beforePath, afterPath, "")); } }; diff --git a/lix/nix/profile.cc b/lix/nix/profile.cc index 0f322790d..6501049af 100644 --- a/lix/nix/profile.cc +++ b/lix/nix/profile.cc @@ -478,10 +478,10 @@ struct CmdProfileDiffClosures : virtual StoreCommand, MixDefaultProfile if (!first) logger->cout(""); first = false; logger->cout("Version %d -> %d:", prevGen->number, gen.number); - printClosureDiff(store, + aio().blockOn(printClosureDiff(store, store->followLinksToStorePath(prevGen->path), store->followLinksToStorePath(gen.path), - " "); + " ")); } prevGen = gen;