CtdlPutSysConfig() don't delete the old copy of the config until after the new one...
authorArt Cancro <ajc@citadel.org>
Fri, 3 Sep 2021 03:55:37 +0000 (03:55 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 3 Sep 2021 03:55:37 +0000 (03:55 +0000)
citadel/config.c

index c84d8f9e4664e9698d5a662746ea7a703abd6b38..bd915f4c4a6a9bad03b992cfa16342cc2dc1497a 100644 (file)
@@ -434,8 +434,7 @@ int CtdlGetConfigInt(char *key)
 /*
  * Fetch a system config value - long integer
  */
-long CtdlGetConfigLong(char *key)
-{
+long CtdlGetConfigLong(char *key) {
        char *s = CtdlGetConfigStr(key);
        if (s) return atol(s);
        return 0;
@@ -447,7 +446,6 @@ void CtdlGetSysConfigBackend(long msgnum, void *userdata) {
 }
 
 
-
 /*
  * This is for fetching longer configuration sets which are stored in the message base.
  */
@@ -506,18 +504,24 @@ char *CtdlGetSysConfig(char *sysconfname) {
 }
 
 
+/*
+ * This is for storing longer configuration sets which are stored in the message base.
+ */
 void CtdlPutSysConfig(char *sysconfname, char *sysconfdata) {
-       long msgnum = -1;
+       long old_msgnum = -1;
+       long new_msgnum = -1;
 
-       // Search for the previous copy of this config item, deleting it if it is found.
-       msgnum = CtdlGetConfigLong(sysconfname);
-       if (msgnum > 0) {
-               CtdlDeleteMessages(SYSCONFIGROOM, &msgnum, 1, "");
-       }
+       // Search for the previous copy of this config item, so we can delete it
+       old_msgnum = CtdlGetConfigLong(sysconfname);
 
        // Go ahead and save it, and write the new msgnum to the config database so we can find it again
-       msgnum = CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 0);
-       if (msgnum > 0) {
-               CtdlSetConfigLong(sysconfname, msgnum);
+       new_msgnum = CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 0);
+       if (new_msgnum > 0) {
+               CtdlSetConfigLong(sysconfname, new_msgnum);
+
+               // Now delete the old copy
+               if (old_msgnum > 0) {
+                       CtdlDeleteMessages(SYSCONFIGROOM, &old_msgnum, 1, "");
+               }
        }
 }