From 4688077187bbdb3f7bcbda11bdc6a1f233e687ab Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 22 Apr 2021 17:48:47 +0200 Subject: [PATCH] PersistModAttrHelper(): only modify attribute if the object config didn't change refs #8717 --- lib/icinga/icingaapplication.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index 561c5327f08..7a0c2a48dff 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -18,6 +18,8 @@ #include "base/initialize.hpp" #include "base/statsfunction.hpp" #include "base/loader.hpp" +#include "base/json.hpp" +#include "base/serializer.hpp" #include using namespace icinga; @@ -138,10 +140,14 @@ static void PersistModAttrHelper(std::fstream& fp, ConfigObject::Ptr& previousOb }); ConfigWriter::EmitFunctionCall(fp, "get_object", args1); - ConfigWriter::EmitRaw(fp, "\nif (obj) {\n"); + ConfigWriter::EmitRaw(fp, "\nif (obj) {\n\tvar result\n"); } - ConfigWriter::EmitRaw(fp, "\tobj."); + ConfigWriter::EmitRaw(fp, "\tif (obj.get_attribute("); + ConfigWriter::EmitString(fp, attr); + ConfigWriter::EmitRaw(fp, ", &result) && Json.encode(Internal.serialize(result, 2 /* FAConfig */)) == "); + ConfigWriter::EmitString(fp, JsonEncode(Serialize(original, FAConfig))); + ConfigWriter::EmitRaw(fp, ") {\n\t\tobj."); Array::Ptr args2 = new Array({ attr, @@ -149,7 +155,7 @@ static void PersistModAttrHelper(std::fstream& fp, ConfigObject::Ptr& previousOb }); ConfigWriter::EmitFunctionCall(fp, "modify_attribute", args2); - ConfigWriter::EmitRaw(fp, "\n"); + ConfigWriter::EmitRaw(fp, "\n\t}\n"); previousObject = object; }