From 6b59ff3184393801bb0b4d96359e2fbfac13f38a Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 16 Oct 2009 20:58:22 +0000 Subject: [PATCH] * Changed my mind about the on-disk format for wiki history. DELETE ANY WIKI ROOMS YOU MAY HAVE ALREADY CREATED. We now do wiki history backwards. In other words, the diffs in each part would be applied top to bottom in order to revert to older and older versions. Theoretically if you apply them all the way through you would end up with an empty page. This will allow revision control to work properly even with a partial history. --- citadel/modules/wiki/serv_wiki.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/citadel/modules/wiki/serv_wiki.c b/citadel/modules/wiki/serv_wiki.c index 65c3a0968..2cab57586 100644 --- a/citadel/modules/wiki/serv_wiki.c +++ b/citadel/modules/wiki/serv_wiki.c @@ -77,7 +77,7 @@ int wiki_upload_beforesave(struct CtdlMessage *msg) { int rv; char history_page[1024]; char boundary[256]; - char endary[260]; + char prefixed_boundary[258]; char buf[1024]; int nbytes = 0; char *diffbuf = NULL; @@ -152,8 +152,8 @@ int wiki_upload_beforesave(struct CtdlMessage *msg) { diffbuf = NULL; snprintf(diff_cmd, sizeof diff_cmd, "diff -u %s %s", - ((old_msg != NULL) ? diff_old_filename : "/dev/null"), - diff_new_filename + diff_new_filename, + ((old_msg != NULL) ? diff_old_filename : "/dev/null") ); fp = popen(diff_cmd, "r"); if (fp != NULL) { @@ -243,26 +243,30 @@ int wiki_upload_beforesave(struct CtdlMessage *msg) { } } while ( (IsEmptyStr(boundary)) && (*ptr != 0) ); + /* Now look for the first boundary. That is where we need to insert our fun. + */ if (!IsEmptyStr(boundary)) { - snprintf(endary, sizeof endary, "--%s--", boundary); + snprintf(prefixed_boundary, sizeof prefixed_boundary, "--%s", boundary); history_msg->cm_fields['M'] = realloc(history_msg->cm_fields['M'], strlen(history_msg->cm_fields['M']) + strlen(diffbuf) + 512 ); - ptr = bmstrcasestr(history_msg->cm_fields['M'], endary); + ptr = bmstrcasestr(history_msg->cm_fields['M'], prefixed_boundary); if (ptr != NULL) { + char *the_rest_of_it = strdup(ptr); sprintf(ptr, "--%s\n" "Content-type: text/plain\n" "From: %s <%s>\n" "\n" "%s\n" - "--%s--\n" + "%s" , boundary, CCC->user.fullname, CCC->cs_inet_email, diffbuf, - boundary + the_rest_of_it ); + free(the_rest_of_it); } history_msg->cm_fields['T'] = realloc(history_msg->cm_fields['T'], 32); -- 2.30.2