conf: allow a WpConf to be loaded without fragments

Use WpProperties to indicate that searching for and loading
conf.d fragments can/should be skipped.

Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
This commit is contained in:
James Calligeros
2024-03-30 16:25:50 +10:00
parent 42666e2054
commit 34040d8e44

View File

@@ -151,7 +151,8 @@ wp_conf_class_init (WpConfClass * klass)
* *
* \ingroup wpconf * \ingroup wpconf
* \param name the name of the configuration file * \param name the name of the configuration file
* \param properties (transfer full) (nullable): unused, reserved for future use * \param properties (transfer full) (nullable): a WpProperties with keys
* specifying how to load the WpConf object
* \returns (transfer full): a new WpConf object * \returns (transfer full): a new WpConf object
*/ */
WpConf * WpConf *
@@ -170,7 +171,8 @@ wp_conf_new (const gchar * name, WpProperties * properties)
* *
* \ingroup wpconf * \ingroup wpconf
* \param name the name of the configuration file * \param name the name of the configuration file
* \param properties (transfer full) (nullable): unused, reserved for future use * \param properties (transfer full) (nullable): a WpProperties with keys
* specifying how to load the WpConf object
* \param error (out) (nullable): return location for a GError, or NULL * \param error (out) (nullable): return location for a GError, or NULL
* \returns (transfer full) (nullable): a new WpConf object, or NULL * \returns (transfer full) (nullable): a new WpConf object, or NULL
* if an error occurred * if an error occurred
@@ -278,12 +280,18 @@ open_and_load_sections (WpConf * self, const gchar *path, GError ** error)
gboolean gboolean
wp_conf_open (WpConf * self, GError ** error) wp_conf_open (WpConf * self, GError ** error)
{ {
const gchar *no_frags = NULL;
g_return_val_if_fail (WP_IS_CONF (self), FALSE); g_return_val_if_fail (WP_IS_CONF (self), FALSE);
g_autofree gchar *path = NULL; g_autofree gchar *path = NULL;
g_autoptr (WpIterator) iterator = NULL; g_autoptr (WpIterator) iterator = NULL;
g_auto (GValue) value = G_VALUE_INIT; g_auto (GValue) value = G_VALUE_INIT;
if (self->properties) {
no_frags = wp_properties_get (self->properties, "no-fragments");
}
/* /*
* open the config file - if the path supplied is absolute, * open the config file - if the path supplied is absolute,
* wp_base_dirs_find_file will ignore WP_BASE_DIRS_CONFIGURATION * wp_base_dirs_find_file will ignore WP_BASE_DIRS_CONFIGURATION
@@ -297,6 +305,7 @@ wp_conf_open (WpConf * self, GError ** error)
g_clear_pointer (&path, g_free); g_clear_pointer (&path, g_free);
/* open the .conf.d/ fragments */ /* open the .conf.d/ fragments */
if (!no_frags) {
path = g_strdup_printf ("%s.d", self->name); path = g_strdup_printf ("%s.d", self->name);
iterator = wp_base_dirs_new_files_iterator (WP_BASE_DIRS_CONFIGURATION, path, iterator = wp_base_dirs_new_files_iterator (WP_BASE_DIRS_CONFIGURATION, path,
".conf"); ".conf");
@@ -312,6 +321,7 @@ wp_conf_open (WpConf * self, GError ** error)
continue; continue;
} }
} }
}
if (self->files->len == 0) { if (self->files->len == 0) {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,