wp: make the config file lookup methods more generic

* Make the flags public and give them nicer names
* Pass down the flags from the caller, so the caller can now explicitly
  ask for looking into specific directories
* Rename the methods
* Remove and inline the wp_get_xdg_config_dir() method, since it's only
  used internally
* Refactor the lookup dirs ordering to get both WIREPLUMBER_*_DIR env
  variables to replace all the other directories. Previously, we were looking
  for scripts in WIREPLUMBER_DATA_DIR, but we were also looking in /etc at
  the same time (with precedence, even), which could result in unexpected
  behaviour. Now, if a WIREPLUMBER environment variable is specified,
  we only look in there.
This commit is contained in:
George Kiagiadakis
2021-08-12 09:08:40 +03:00
parent 129b44bb0c
commit 27ed36c2da
5 changed files with 68 additions and 114 deletions

View File

@@ -99,6 +99,12 @@ load_file (const GValue *item, GValue *ret, gpointer data)
return TRUE;
}
#define CONFIG_DIRS_LOOKUP_SET \
(WP_LOOKUP_DIR_ENV_CONFIG | \
WP_LOOKUP_DIR_XDG_CONFIG_HOME | \
WP_LOOKUP_DIR_ETC | \
WP_LOOKUP_DIR_PREFIX_SHARE)
gboolean
wp_lua_scripting_load_configuration (const gchar * conf_file,
WpCore * core, GError ** error)
@@ -112,7 +118,7 @@ wp_lua_scripting_load_configuration (const gchar * conf_file,
wplua_enable_sandbox (L, WP_LUA_SANDBOX_MINIMAL_STD);
/* load conf_file itself */
path = wp_find_config_file (conf_file, NULL);
path = wp_find_file (CONFIG_DIRS_LOOKUP_SET, conf_file, NULL);
if (path) {
wp_info ("loading config file: %s", path);
if (!wplua_load_path (L, path, 0, 0, error))
@@ -122,7 +128,7 @@ wp_lua_scripting_load_configuration (const gchar * conf_file,
g_clear_pointer (&path, g_free);
path = g_strdup_printf ("%s.d", conf_file);
it = wp_new_config_files_iterator (path, ".lua");
it = wp_new_files_iterator (CONFIG_DIRS_LOOKUP_SET, path, ".lua");
g_value_init (&fold_ret, G_TYPE_INT);
g_value_set_int (&fold_ret, nfiles);