void FinishEditContext(EvalContext *ctx, EditContext *ec, Attributes a, const Promise *pp) { if (DONTDO || (a.transaction.action == cfa_warn)) { if (ec && (!CompareToFile(ctx, ec->file_start, ec->filename, a, pp)) && (ec->num_edits > 0)) { cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_WARN, pp, a, "Should edit file '%s' but only a warning promised", ec->filename); } return; } else if (ec && (ec->num_edits > 0)) { if (a.haveeditline) { if (CompareToFile(ctx, ec->file_start, ec->filename, a, pp)) { if (ec) { cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "No edit changes to file '%s' need saving", ec->filename); } } else { if (SaveItemListAsFile(ec->file_start, ec->filename, a)) { cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_CHANGE, pp, a, "Edit file '%s'", ec->filename); } else { cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Unable to save file '%s' after editing", ec->filename); } } } if (a.haveeditxml) { #ifdef HAVE_LIBXML2 if (XmlCompareToFile(ec->xmldoc, ec->filename, a.edits)) { if (ec) { cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "No edit changes to xml file '%s' need saving", ec->filename); } } else { if (SaveXmlDocAsFile(ec->xmldoc, ec->filename, a)) { cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_CHANGE, pp, a, "Edited xml file '%s'", ec->filename); } else { cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Failed to edit XML file '%s'", ec->filename); } } xmlFreeDoc(ec->xmldoc); #else cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Cannot edit XML files without LIBXML2"); #endif } } else { if (ec) { cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, a, "No edit changes to file '%s' need saving", ec->filename); } } if (ec != NULL) { DeleteItemList(ec->file_start); } }
void FinishEditContext(EvalContext *ctx, EditContext *ec, Attributes a, Promise *pp) { Item *ip; EDIT_MODEL = false; if (DONTDO || (a.transaction.action == cfa_warn)) { if (ec && (!CompareToFile(ctx, ec->file_start, ec->filename, a, pp)) && (ec->num_edits > 0)) { cfPS(ctx, OUTPUT_LEVEL_ERROR, CF_WARN, "", pp, a, " -> Should edit file %s but only a warning promised", ec->filename); } return; } else if (ec && (ec->num_edits > 0)) { if (a.haveeditline) { if (CompareToFile(ctx, ec->file_start, ec->filename, a, pp)) { if (ec) { cfPS(ctx, OUTPUT_LEVEL_VERBOSE, CF_NOP, "", pp, a, " -> No edit changes to file %s need saving", ec->filename); } } else { SaveItemListAsFile(ctx, ec->file_start, ec->filename, a, pp); } } if (a.haveeditxml) { #ifdef HAVE_LIBXML2 if (XmlCompareToFile(ctx, ec->xmldoc, ec->filename, a, pp)) { if (ec) { cfPS(ctx, OUTPUT_LEVEL_VERBOSE, CF_NOP, "", pp, a, " -> No edit changes to xml file %s need saving", ec->filename); } } else { SaveXmlDocAsFile(ctx, ec->xmldoc, ec->filename, a, pp); } xmlFreeDoc(ec->xmldoc); #else cfPS(ctx, OUTPUT_LEVEL_ERROR, CF_FAIL, "", pp, a, " !! Cannot edit XML files without LIBXML2\n"); #endif } } else { if (ec) { cfPS(ctx, OUTPUT_LEVEL_VERBOSE, CF_NOP, "", pp, a, " -> No edit changes to file %s need saving", ec->filename); } } if (ec != NULL) { for (ip = ec->file_classes; ip != NULL; ip = ip->next) { EvalContextHeapAddSoft(ctx, ip->name, PromiseGetNamespace(pp)); } DeleteItemList(ec->file_classes); DeleteItemList(ec->file_start); } }