lib: add functions to search in configuration/data directories

The previous approach to loading config files was to ask WP for the
directory and then search those for the config files. This patch changes the
approach - a caller now asks WP to search for a specific config file or
iterate over a config file directory.

This allows us to implement a directory lookup order, i.e.
"wireplumber.conf" may be in XDG_CONFIG_DIR, /etc/,
/usr/share and the first one found is used.

For configuration directories, the new method iterates over all matching
entries (files + directories) and invokes a callback for each entry.

This enables distributions to ship default files in /usr/share/wireplumber
but have admins and users override them on a local basis. For lua scripts in
particular, overriding a distribution-provided file with an empty file
effectively disables it, adding a file adds it in the right sort order.
This commit is contained in:
Peter Hutterer
2021-07-07 16:09:34 +10:00
committed by George Kiagiadakis
parent 153e84c8b8
commit d38c3fb4cc
6 changed files with 261 additions and 95 deletions

View File

@@ -131,39 +131,7 @@ find_script (const gchar * script, gboolean daemon)
g_file_test (script, G_FILE_TEST_IS_REGULAR))
return g_strdup (script);
/* /etc/wireplumber/scripts */
{
g_autofree gchar * file = g_build_filename (
wp_get_config_dir (), "scripts", script, NULL);
wp_trace ("trying %s", file);
if (g_file_test (file, G_FILE_TEST_IS_REGULAR))
return g_steal_pointer (&file);
}
{
g_autofree gchar * file = g_build_filename (
wp_get_data_dir (), "scripts", script, NULL);
wp_trace ("trying %s", file);
if (g_file_test (file, G_FILE_TEST_IS_REGULAR))
return g_steal_pointer (&file);
}
/* {XDG_DATA_DIRS,/usr/local/share,/usr/share}/wireplumber/scripts */
const gchar * const * data_dirs = g_get_system_data_dirs ();
for (; *data_dirs; data_dirs++) {
g_autofree gchar * file = g_build_filename (
*data_dirs, "wireplumber", "scripts", script, NULL);
wp_trace ("trying %s", file);
if (g_file_test (file, G_FILE_TEST_IS_REGULAR))
return g_steal_pointer (&file);
}
return NULL;
return wp_find_sysconfig_file (script, "scripts");
}
static gboolean