libstore: asyncify Store::topoSortPaths
Change-Id: Iaad42a6f021434a5f160c88ca7c8afe6ff280806
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ void StorePathsCommand::run(ref<Store> 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));
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace nix {
|
||||
|
||||
kj::Promise<Result<void>> 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) {
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -356,9 +356,9 @@ void Store::queryMissing(const std::vector<DerivedPath> & targets,
|
||||
}
|
||||
|
||||
|
||||
StorePaths Store::topoSortPaths(const StorePathSet & paths)
|
||||
{
|
||||
return topoSort(paths,
|
||||
kj::Promise<Result<StorePaths>> 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<Result<std::map<DrvOutput, StorePath>>> drvOutputReferences(
|
||||
|
||||
@@ -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<StorePath, StorePath> pathsMap;
|
||||
|
||||
@@ -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<Result<StorePaths>> topoSortPaths(const StorePathSet & paths);
|
||||
|
||||
/**
|
||||
* Export multiple paths in the format expected by ‘nix-store
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user