Commits

Richard Goedeken committed 84c6ea3

bugfix: when the front-end specifies an override for the configuration directory, always use this path, so that we don't load the config from there and then save it back to the default user path

  • Participants
  • Parent commits 135a179

Comments (0)

Files changed (1)

File src/api/config.c

 static int         l_ConfigInit = 0;
 static int         l_SaveConfigOnExit = 0;
 static char       *l_DataDirOverride = NULL;
+static char       *l_ConfigDirOverride = NULL;
 static config_list l_ConfigListActive = NULL;
 static config_list l_ConfigListSaved = NULL;
 
         strcpy(l_DataDirOverride, DataDirOverride);
     }
 
+    /* if a config directory was specified, make a copy of it */
+    if (ConfigDirOverride != NULL)
+    {
+        l_ConfigDirOverride = (char *) malloc(strlen(ConfigDirOverride) + 1);
+        if (l_ConfigDirOverride == NULL)
+            return M64ERR_NO_MEMORY;
+        strcpy(l_ConfigDirOverride, ConfigDirOverride);
+    }
+
+
     /* get the full pathname to the config file and try to open it */
-    if (ConfigDirOverride != NULL)
-        configpath = ConfigDirOverride;
-    else
-    {
-        configpath = ConfigGetUserConfigPath();
-        if (configpath == NULL)
-            return M64ERR_FILES;
-    }
+    configpath = ConfigGetUserConfigPath();
+    if (configpath == NULL)
+        return M64ERR_FILES;
 
     filepath = (char *) malloc(strlen(configpath) + 32);
     if (filepath == NULL)
         free(l_DataDirOverride);
         l_DataDirOverride = NULL;
     }
+    if (l_ConfigDirOverride != NULL)
+    {
+        free(l_ConfigDirOverride);
+        l_ConfigDirOverride = NULL;
+    }
 
     /* free all of the memory in the 2 lists */
     delete_list(&l_ConfigListActive);
 
 EXPORT const char * CALL ConfigGetUserConfigPath(void)
 {
-  return osal_get_user_configpath();
+    if (l_ConfigDirOverride != NULL)
+        return l_ConfigDirOverride;
+    else
+        return osal_get_user_configpath();
 }
 
 EXPORT const char * CALL ConfigGetUserDataPath(void)