Skip to content

Commit

Permalink
PersistModAttrHelper(): only modify attribute if the object config di…
Browse files Browse the repository at this point in the history
…dn't change

refs #8717
  • Loading branch information
Al2Klimov committed Apr 22, 2021
1 parent 6e606ad commit 4688077
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/icinga/icingaapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fstream>

using namespace icinga;
Expand Down Expand Up @@ -138,18 +140,22 @@ 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,
modified
});
ConfigWriter::EmitFunctionCall(fp, "modify_attribute", args2);

ConfigWriter::EmitRaw(fp, "\n");
ConfigWriter::EmitRaw(fp, "\n\t}\n");

previousObject = object;
}
Expand Down

0 comments on commit 4688077

Please sign in to comment.