Skip to content
Extraits de code Groupes Projets
Vérifiée Valider f1c4be72 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

CONFIG: Ensure that optional fields are present at least with their default values

parent e704136b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!170Ensure that option config values are present in the db
Pipeline #2315 en échec
...@@ -173,6 +173,7 @@ bool database_config_get_int (lkt_db *db, const char *section, const cha ...@@ -173,6 +173,7 @@ bool database_config_get_int (lkt_db *db, const char *section, const cha
bool database_config_exists (lkt_db *db, const char *section, const char *key); bool database_config_exists (lkt_db *db, const char *section, const char *key);
bool database_config_queue (lkt_db *db, const char *option, int value); bool database_config_queue (lkt_db *db, const char *option, int value);
bool database_config_queue_default (lkt_db *db); bool database_config_queue_default (lkt_db *db);
void database_config_set_optional_fields(lkt_db *db);
/* Dump configuration to any stream, form is undefined, this function is here /* Dump configuration to any stream, form is undefined, this function is here
* for debug purpose. */ * for debug purpose. */
......
...@@ -275,6 +275,10 @@ config_new(lkt_db *db, const char *conf) ...@@ -275,6 +275,10 @@ config_new(lkt_db *db, const char *conf)
goto error; goto error;
} }
LOG_INFO("CONFIG", "Ensure that optional fields are present: set then to default "
"value if not present");
database_config_set_optional_fields(db);
return 0; return 0;
error: error:
LOG_ERROR("CONFIG", "Errors detected, here is a default config"); LOG_ERROR("CONFIG", "Errors detected, here is a default config");
......
...@@ -146,6 +146,23 @@ error: ...@@ -146,6 +146,23 @@ error:
return ret; return ret;
} }
void
database_config_set_optional_fields(lkt_db *db)
{
const char *section;
#define section(_sct) section = _sct;
#define value(name, value)
#define value_opt(name, value) \
if (!database_config_exists(db, section, name)) { \
FAIL_UNLESS(database_config_set(db, section, name, value), "Failed to set default value for option '%s/" #name "'", section); \
}
#include <lektor/config.def>
#undef section
#undef value
#undef value_opt
}
bool bool
database_validate_conf(lkt_db *db) database_validate_conf(lkt_db *db)
{ {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter