Skip to content

Commit 59286db

Browse files
committed
Don't compare files after mustache rendering
When using template method `"mustache"` and `"inline_mustache"` the the rendered file is already saved in RenderTemplateMustache(). When calling FinishEditContext() later on to free up memory, it would compare the edit context to the rendered file and change the promise result to NOOP. Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
1 parent dd79a5a commit 59286db

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

cf-agent/files_edit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ EditContext *NewEditContext(char *filename, const Attributes *a)
103103
/*****************************************************************************/
104104

105105
void FinishEditContext(EvalContext *ctx, EditContext *ec, const Attributes *a, const Promise *pp,
106-
PromiseResult *result)
106+
PromiseResult *result, bool do_not_save_file_as)
107107
{
108-
if (*result != PROMISE_RESULT_CHANGE)
108+
if (*result != PROMISE_RESULT_CHANGE || do_not_save_file_as)
109109
{
110110
// Failure or skipped. Don't update the file.
111111
goto end;

cf-agent/files_edit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ typedef struct
5757
EditContext *NewEditContext(char *filename, const Attributes *a);
5858
void FinishEditContext(EvalContext *ctx, EditContext *ec,
5959
const Attributes *a, const Promise *pp,
60-
PromiseResult *result);
60+
PromiseResult *result, bool do_not_save_file_as);
6161

6262
#ifdef HAVE_LIBXML2
6363
bool LoadFileAsXmlDoc(xmlDocPtr *doc, const char *file, EditDefaults ed, bool only_checks);

cf-agent/verify_files.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,10 @@ PromiseResult ScheduleEditOperation(EvalContext *ctx, char *filename,
11051105
}
11061106

11071107
exit:
1108-
FinishEditContext(ctx, edcontext, a, pp, &result);
1108+
/* With template method "mustache" and "inline_mustache" the file is
1109+
* already saved. Saving it again will result in PROMISE_RESULT_NOOP */
1110+
bool do_not_save_file_as = StringEqual(a->template_method, "mustache") || StringEqual(a->template_method, "inline_mustache");
1111+
FinishEditContext(ctx, edcontext, a, pp, &result, do_not_save_file_as);
11091112
YieldCurrentLock(thislock);
11101113
if (result == PROMISE_RESULT_CHANGE)
11111114
{

0 commit comments

Comments
 (0)