Skip to content

Commit a88a0df

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 a88a0df

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-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 no_compare)
107107
{
108-
if (*result != PROMISE_RESULT_CHANGE)
108+
if (*result != PROMISE_RESULT_CHANGE || no_compare)
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 no_compare);
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,11 @@ 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. Hence, comparing the file to the edit context would
1110+
* result in PROMISE_RESULT_NOOP. */
1111+
bool no_compare = StringEqual(a->template_method, "mustache") || StringEqual(a->template_method, "inline_mustache");
1112+
FinishEditContext(ctx, edcontext, a, pp, &result, no_compare);
11091113
YieldCurrentLock(thislock);
11101114
if (result == PROMISE_RESULT_CHANGE)
11111115
{

0 commit comments

Comments
 (0)