diff --git a/lix/legacy/nix-store.cc b/lix/legacy/nix-store.cc index 078ee4e6e..e75e51445 100644 --- a/lix/legacy/nix-store.cc +++ b/lix/legacy/nix-store.cc @@ -265,7 +265,7 @@ try { /* Some code to print a tree representation of a derivation dependency graph. Topological sorting is used to keep the tree relatively flat. */ -static void printTree(const StorePath & path, +static void printTree(AsyncIoRoot & aio, const StorePath & path, const std::string & firstPad, const std::string & tailPad, StorePathSet & done) { if (!done.insert(path).second) { @@ -281,12 +281,12 @@ static void printTree(const StorePath & path, closure(B). That is, if derivation A is an (possibly indirect) input of B, then A is printed first. This has the effect of flattening the tree, preventing deeply nested structures. */ - auto sorted = store->topoSortPaths(info->references); + auto sorted = aio.blockOn(store->topoSortPaths(info->references)); reverse(sorted.begin(), sorted.end()); for (const auto &[n, i] : enumerate(sorted)) { bool last = n + 1 == sorted.size(); - printTree(i, + printTree(aio, i, tailPad + (last ? treeLast : treeConn), tailPad + (last ? treeNull : treeLine), done); @@ -378,7 +378,7 @@ static void opQuery(AsyncIoRoot & aio, Strings opFlags, Strings opArgs) aio.blockOn(store->computeFSClosure(j, paths, true)); } } - auto sorted = store->topoSortPaths(paths); + auto sorted = aio.blockOn(store->topoSortPaths(paths)); for (StorePaths::reverse_iterator i = sorted.rbegin(); i != sorted.rend(); ++i) cout << fmt("%s\n", store->printStorePath(*i)); @@ -400,7 +400,7 @@ static void opQuery(AsyncIoRoot & aio, Strings opFlags, Strings opArgs) result.insert(i); } } - auto sorted = store->topoSortPaths(result); + auto sorted = aio.blockOn(store->topoSortPaths(result)); for (StorePaths::reverse_iterator i = sorted.rbegin(); i != sorted.rend(); ++i) cout << fmt("%s\n", store->printStorePath(*i)); @@ -436,7 +436,7 @@ static void opQuery(AsyncIoRoot & aio, Strings opFlags, Strings opArgs) case qTree: { StorePathSet done; for (auto & i : opArgs) - printTree(store->followLinksToStorePath(i), "", "", done); + printTree(aio, store->followLinksToStorePath(i), "", "", done); break; } diff --git a/lix/libcmd/command.cc b/lix/libcmd/command.cc index 8c5bd190b..d3b1f0999 100644 --- a/lix/libcmd/command.cc +++ b/lix/libcmd/command.cc @@ -199,7 +199,7 @@ void StorePathsCommand::run(ref store, BuiltPaths && paths) for (auto & p : builtPath.outPaths()) storePaths.insert(p); - auto sorted = store->topoSortPaths(storePaths); + auto sorted = aio().blockOn(store->topoSortPaths(storePaths)); std::reverse(sorted.begin(), sorted.end()); run(store, std::move(sorted)); diff --git a/lix/libmain/shared.cc b/lix/libmain/shared.cc index d5aeb4824..4cb8728c9 100644 --- a/lix/libmain/shared.cc +++ b/lix/libmain/shared.cc @@ -69,7 +69,7 @@ try { printMsg(lvl, "this derivation will be built:"); else printMsg(lvl, "these %d derivations will be built:", willBuild.size()); - auto sorted = store->topoSortPaths(willBuild); + auto sorted = TRY_AWAIT(store->topoSortPaths(willBuild)); reverse(sorted.begin(), sorted.end()); for (auto & i : sorted) printMsg(lvl, " %s", store->printStorePath(i)); diff --git a/lix/libstore/export-import.cc b/lix/libstore/export-import.cc index f19618e0a..d8fcc39fc 100644 --- a/lix/libstore/export-import.cc +++ b/lix/libstore/export-import.cc @@ -11,7 +11,7 @@ namespace nix { kj::Promise> Store::exportPaths(const StorePathSet & paths, Sink & sink) try { - auto sorted = topoSortPaths(paths); + auto sorted = TRY_AWAIT(topoSortPaths(paths)); std::reverse(sorted.begin(), sorted.end()); for (auto & path : sorted) { diff --git a/lix/libstore/gc.cc b/lix/libstore/gc.cc index fba40ce29..2066cda02 100644 --- a/lix/libstore/gc.cc +++ b/lix/libstore/gc.cc @@ -783,7 +783,7 @@ try { } } - for (auto & path : topoSortPaths(visited)) { + for (auto & path : TRY_AWAIT(topoSortPaths(visited))) { if (!dead.insert(path).second) continue; if (shouldDelete) { try { diff --git a/lix/libstore/make-content-addressed.cc b/lix/libstore/make-content-addressed.cc index 3244cf64b..c4e2c8a88 100644 --- a/lix/libstore/make-content-addressed.cc +++ b/lix/libstore/make-content-addressed.cc @@ -13,7 +13,7 @@ try { StorePathSet closure; TRY_AWAIT(srcStore.computeFSClosure(storePaths, closure)); - auto paths = srcStore.topoSortPaths(closure); + auto paths = TRY_AWAIT(srcStore.topoSortPaths(closure)); std::reverse(paths.begin(), paths.end()); diff --git a/lix/libstore/misc.cc b/lix/libstore/misc.cc index fedcf6235..bea93256c 100644 --- a/lix/libstore/misc.cc +++ b/lix/libstore/misc.cc @@ -356,9 +356,9 @@ void Store::queryMissing(const std::vector & targets, } -StorePaths Store::topoSortPaths(const StorePathSet & paths) -{ - return topoSort(paths, +kj::Promise> Store::topoSortPaths(const StorePathSet & paths) +try { + co_return topoSort(paths, {[&](const StorePath & path) { try { return queryPathInfo(path)->references; @@ -372,6 +372,8 @@ StorePaths Store::topoSortPaths(const StorePathSet & paths) printStorePath(path), printStorePath(parent)); }}); +} catch (...) { + co_return result::current_exception(); } static kj::Promise>> drvOutputReferences( diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index 733f60b4b..e51c95e1e 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -1237,7 +1237,7 @@ try { // In the general case, `addMultipleToStore` requires a sorted list of // store paths to add, so sort them right now - auto sortedMissing = srcStore.topoSortPaths(missing); + auto sortedMissing = TRY_AWAIT(srcStore.topoSortPaths(missing)); std::reverse(sortedMissing.begin(), sortedMissing.end()); std::map pathsMap; diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index 14b814bf8..02db64ca0 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -790,7 +790,7 @@ public: * Sort a set of paths topologically under the references * relation. If p refers to q, then p precedes q in this list. */ - StorePaths topoSortPaths(const StorePathSet & paths); + kj::Promise> topoSortPaths(const StorePathSet & paths); /** * Export multiple paths in the format expected by ‘nix-store diff --git a/perl/lib/Nix/Store.xs b/perl/lib/Nix/Store.xs index c4e24e497..de6884ca0 100644 --- a/perl/lib/Nix/Store.xs +++ b/perl/lib/Nix/Store.xs @@ -174,7 +174,7 @@ SV * topoSortPaths(...) try { StorePathSet paths; for (int n = 0; n < items; ++n) paths.insert(store()->parseStorePath(SvPV_nolen(ST(n)))); - auto sorted = store()->topoSortPaths(paths); + auto sorted = aio().blockOn(store()->topoSortPaths(paths)); for (auto & i : sorted) XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(i).c_str(), 0))); } catch (Error & e) {