(config_file) Enable saving of changed parameters when '#include' directives are used

This commit is contained in:
jdgleaver 2020-11-09 11:18:49 +00:00
parent 3693db2451
commit 317ad3181d

View File

@ -1053,11 +1053,7 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)
if (entry) if (entry)
{ {
/* An entry corresponding to 'key' already exists /* An entry corresponding to 'key' already exists
* > Check if it's read only */ * > Check whether value is currently set */
if (entry->readonly)
return;
/* Check whether value is currently set */
if (entry->value) if (entry->value)
{ {
/* Do nothing if value is unchanged */ /* Do nothing if value is unchanged */
@ -1069,9 +1065,12 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)
free(entry->value); free(entry->value);
} }
/* Update value */ /* Update value
entry->value = strdup(val); * > Note that once a value is set, it
conf->modified = true; * is no longer considered 'read only' */
entry->value = strdup(val);
entry->readonly = false;
conf->modified = true;
return; return;
} }
} }
@ -1245,14 +1244,6 @@ void config_file_dump_orbis(config_file_t *conf, int fd)
{ {
struct config_entry_list *list = NULL; struct config_entry_list *list = NULL;
struct config_include_list *includes = conf->includes; struct config_include_list *includes = conf->includes;
while (includes)
{
char cad[256];
snprintf(cad, sizeof(cad),
"#include %s\n", includes->path);
orbisWrite(fd, cad, strlen(cad));
includes = includes->next;
}
list = config_file_merge_sort_linked_list( list = config_file_merge_sort_linked_list(
(struct config_entry_list*)conf->entries, (struct config_entry_list*)conf->entries,
@ -1270,6 +1261,21 @@ void config_file_dump_orbis(config_file_t *conf, int fd)
} }
list = list->next; list = list->next;
} }
/* Config files are read from the top down - if
* duplicate entries are found then the topmost
* one in the list takes precedence. This means
* '#include' directives must go *after* individual
* config entries, otherwise they will override
* any custom-set values */
while (includes)
{
char cad[256];
snprintf(cad, sizeof(cad),
"#include %s\n", includes->path);
orbisWrite(fd, cad, strlen(cad));
includes = includes->next;
}
} }
#endif #endif
@ -1278,12 +1284,6 @@ void config_file_dump(config_file_t *conf, FILE *file, bool sort)
struct config_entry_list *list = NULL; struct config_entry_list *list = NULL;
struct config_include_list *includes = conf->includes; struct config_include_list *includes = conf->includes;
while (includes)
{
fprintf(file, "#include \"%s\"\n", includes->path);
includes = includes->next;
}
if (sort) if (sort)
list = config_file_merge_sort_linked_list( list = config_file_merge_sort_linked_list(
(struct config_entry_list*)conf->entries, (struct config_entry_list*)conf->entries,
@ -1299,6 +1299,18 @@ void config_file_dump(config_file_t *conf, FILE *file, bool sort)
fprintf(file, "%s = \"%s\"\n", list->key, list->value); fprintf(file, "%s = \"%s\"\n", list->key, list->value);
list = list->next; list = list->next;
} }
/* Config files are read from the top down - if
* duplicate entries are found then the topmost
* one in the list takes precedence. This means
* '#include' directives must go *after* individual
* config entries, otherwise they will override
* any custom-set values */
while (includes)
{
fprintf(file, "#include \"%s\"\n", includes->path);
includes = includes->next;
}
} }
bool config_entry_exists(config_file_t *conf, const char *entry) bool config_entry_exists(config_file_t *conf, const char *entry)