From cd92ea588504db697103d3ff56166fe61e6da131 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 19 Feb 2022 22:34:50 +0100 Subject: libstore/derivation-goal: avoid double-parsing of JSON messages To avoid that JSON messages are parsed twice in case of remote builds with `ssh-ng://`, I split up the original `handleJSONLogMessage` into three parts: * `parseJSONMessage(const std::string&)` checks if it's a message in the form of `@nix {...}` and tries to parse it (and prints an error if the parsing fails). * `handleJSONLogMessage(nlohmann::json&, ...)` reads the fields from the message and passes them to the logger. * `handleJSONLogMessage(const std::string&, ...)` behaves as before, but uses the two functions mentioned above as implementation. In case of `ssh-ng://`-logs the first two methods are invoked manually. --- src/libutil/logging.hh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/libutil/logging.hh') diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index bd28036ae..9ab2091c7 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -4,6 +4,8 @@ #include "error.hh" #include "config.hh" +#include + namespace nix { typedef enum { @@ -166,6 +168,12 @@ Logger * makeSimpleLogger(bool printBuildLogs = true); Logger * makeJSONLogger(Logger & prevLogger); +std::optional parseJSONMessage(const std::string & msg); + +bool handleJSONLogMessage(nlohmann::json & json, + const Activity & act, std::map & activities, + bool trusted); + bool handleJSONLogMessage(const std::string & msg, const Activity & act, std::map & activities, bool trusted); -- cgit v1.2.3