From bc0e0786f087ff7950c1aef47111201805338f3b Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 21 Feb 2025 00:35:11 +0100 Subject: [PATCH] libstore: asyncify Store::getClosureSize Change-Id: I625c92f94e2a77b64569d385d486434ae41df2da --- lix/libstore/store-api.cc | 11 +++++++---- lix/libstore/store-api.hh | 2 +- lix/nix/path-info.cc | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index 9262d6c89..8dee25296 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -1002,7 +1002,7 @@ try { std::pair closureSizes; if (showClosureSize) { - closureSizes = getClosureSize(info->path); + closureSizes = TRY_AWAIT(getClosureSize(info->path)); jsonPath["closureSize"] = closureSizes.first; } @@ -1048,8 +1048,9 @@ try { } -std::pair Store::getClosureSize(const StorePath & storePath) -{ +kj::Promise>> +Store::getClosureSize(const StorePath & storePath) +try { uint64_t totalNarSize = 0, totalDownloadSize = 0; StorePathSet closure; computeFSClosure(storePath, closure, false, false); @@ -1061,7 +1062,9 @@ std::pair Store::getClosureSize(const StorePath & storePath) if (narInfo) totalDownloadSize += narInfo->fileSize; } - return {totalNarSize, totalDownloadSize}; + co_return {totalNarSize, totalDownloadSize}; +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index cbb1d0d87..46e921ccd 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -702,7 +702,7 @@ public: * the sum of the size of the NAR serialisation of each path in the * closure. */ - std::pair getClosureSize(const StorePath & storePath); + kj::Promise>> getClosureSize(const StorePath & storePath); /** * Optimise the disk space usage of the Nix store by hard-linking files diff --git a/lix/nix/path-info.cc b/lix/nix/path-info.cc index ba3e5a887..e98b8d153 100644 --- a/lix/nix/path-info.cc +++ b/lix/nix/path-info.cc @@ -112,7 +112,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON printSize(info->narSize); if (showClosureSize) - printSize(store->getClosureSize(info->path).first); + printSize(aio().blockOn(store->getClosureSize(info->path)).first); if (showSigs) { std::cout << '\t';