From 98cb3014e8ba9142ab5a8d5b667c9eaef2fbc4a3 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 18 Jan 2026 19:20:35 +0100 Subject: [PATCH] legacycmd: don't print to stdout from printDotGraph return a string instead, and write that to stdout explicitly. Change-Id: I21e7a1eb22f2772e31b754823f64f941be080c56 --- lix/legacy/dotgraph.cc | 18 ++++++++---------- lix/legacy/dotgraph.hh | 3 +-- lix/legacy/nix-store.cc | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lix/legacy/dotgraph.cc b/lix/legacy/dotgraph.cc index cd7e8e75e..b60bb1cd0 100644 --- a/lix/legacy/dotgraph.cc +++ b/lix/legacy/dotgraph.cc @@ -4,9 +4,7 @@ #include "lix/libutil/result.hh" #include - - -using std::cout; +#include namespace nix { @@ -42,31 +40,31 @@ static std::string makeNode(std::string_view id, std::string_view label, dotQuote(id), dotQuote(label), dotQuote(colour)); } - -kj::Promise> printDotGraph(ref store, StorePathSet && roots) +kj::Promise> printDotGraph(ref store, StorePathSet && roots) try { StorePathSet workList(std::move(roots)); StorePathSet doneSet; + std::stringstream result; - cout << "digraph G {\n"; + result << "digraph G {\n"; while (!workList.empty()) { auto path = std::move(workList.extract(workList.begin()).value()); if (!doneSet.insert(path).second) continue; - cout << makeNode(std::string(path.to_string()), path.name(), "#ff0000"); + result << makeNode(std::string(path.to_string()), path.name(), "#ff0000"); for (auto & p : TRY_AWAIT(store->queryPathInfo(path))->references) { if (p != path) { workList.insert(p); - cout << makeEdge(std::string(p.to_string()), std::string(path.to_string())); + result << makeEdge(std::string(p.to_string()), std::string(path.to_string())); } } } - cout << "}\n"; - co_return result::success(); + result << "}\n"; + co_return result.str(); } catch (...) { co_return result::current_exception(); } diff --git a/lix/legacy/dotgraph.hh b/lix/legacy/dotgraph.hh index 2175ca2d6..49c801b6a 100644 --- a/lix/legacy/dotgraph.hh +++ b/lix/legacy/dotgraph.hh @@ -5,6 +5,5 @@ namespace nix { -kj::Promise> printDotGraph(ref store, StorePathSet && roots); - +kj::Promise> printDotGraph(ref store, StorePathSet && roots); } diff --git a/lix/legacy/nix-store.cc b/lix/legacy/nix-store.cc index b72640814..6672b41bb 100644 --- a/lix/legacy/nix-store.cc +++ b/lix/legacy/nix-store.cc @@ -490,7 +490,7 @@ opQuery(std::shared_ptr store, AsyncIoRoot & aio, Strings opFlags, String { roots.insert(j); } - aio.blockOn(printDotGraph(ref::unsafeFromPtr(store), std::move(roots))); + std::cout << aio.blockOn(printDotGraph(ref::unsafeFromPtr(store), std::move(roots))); break; }