--- a/gplugin/gplugin-manager.c Thu Oct 14 23:11:27 2021 -0500
+++ b/gplugin/gplugin-manager.c Sat Oct 23 02:03:59 2021 -0500
@@ -125,6 +125,36 @@
+gplugin_manager_change_paths_from_environment( + GPluginManager *manager, + void (*changer)(GPluginManager *, const gchar *); + from_env = g_getenv(name); + paths = g_strsplit(from_env, G_SEARCHPATH_SEPARATOR_S, 0); + changer = &gplugin_manager_prepend_path; + changer = &gplugin_manager_append_path; + for(i = 0; paths[i]; i++) { + (*changer)(manager, paths[i]); gplugin_manager_foreach_unload_plugin(
@@ -685,6 +715,40 @@
+ * gplugin_manager_append_paths_from_environment: + * @manager: The manager instance. + * @name: The name of the environment variable containing the paths to add. + * Append the paths held in the environment variable @name to the list. +gplugin_manager_append_paths_from_environment( + GPluginManager *manager, + gplugin_manager_change_paths_from_environment(manager, name, FALSE); + * gplugin_manager_prepend_paths_from_environment: + * @manager: The manager instance. + * @name: The name of the environment variable containing the paths to add. + * Prepends the paths held in the environment variable @name to the list. +gplugin_manager_prepend_paths_from_environment( + GPluginManager *manager, + gplugin_manager_change_paths_from_environment(manager, name, TRUE); * gplugin_manager_get_paths:
* @manager: The manager instance.
--- a/gplugin/gplugin-manager.h Thu Oct 14 23:11:27 2021 -0500
+++ b/gplugin/gplugin-manager.h Sat Oct 23 02:03:59 2021 -0500
@@ -30,12 +30,7 @@
#define GPLUGIN_TYPE_MANAGER (gplugin_manager_get_type())
+G_DECLARE_FINAL_TYPE(GPluginManager, gplugin_manager, GPLUGIN, MANAGER, GObject) typedef void (*GPluginManagerForeachFunc)(
@@ -52,6 +47,12 @@
+void gplugin_manager_append_paths_from_environment( + GPluginManager *manager, +void gplugin_manager_prepend_paths_from_environment( + GPluginManager *manager, GList *gplugin_manager_get_paths(GPluginManager *manager);
--- a/gplugin/tests/test-plugin-manager-paths.c Thu Oct 14 23:11:27 2021 -0500
+++ b/gplugin/tests/test-plugin-manager-paths.c Sat Oct 23 02:03:59 2021 -0500
@@ -221,6 +221,72 @@
g_assert_cmpuint(0, ==, size);
+test_gplugin_manager_add_app_paths_via_environ(void) + GList *paths = NULL, *l = NULL; + gchar *pre_paths, *post_paths; + const gchar *pre_env_var_name = "GPLUGIN_EXTRA_TEST_PREPATHS"; + const gchar *post_env_var_name = "GPLUGIN_EXTRA_TEST_POSTPATHS"; + GPluginManager *manager = gplugin_manager_get_default(); + /* get number of paths to start */ + paths = gplugin_manager_get_paths(manager); + path_count = g_list_length(paths); + /* build contents of environment vars */ + pre_paths = g_strdup_printf( + G_SEARCHPATH_SEPARATOR_S, + post_paths = g_strdup_printf( + G_SEARCHPATH_SEPARATOR_S, + /* put /envfoo and /envbar as paths in an environment variable */ + g_setenv(pre_env_var_name, pre_paths, TRUE); + g_setenv(post_env_var_name, post_paths, TRUE); + /* have the manager add them */ + gplugin_manager_prepend_paths_from_environment(manager, pre_env_var_name); + gplugin_manager_append_paths_from_environment(manager, post_env_var_name); + /* now get the manager's current paths */ + paths = gplugin_manager_get_paths(manager); + /* four more paths now */ + test_path_count(manager, path_count + 4); + /* check order is correct */ + for(l = paths; l != NULL; l = l->next) { + if(g_strcmp0(l->data, "/prefoo/") == 0) { + g_assert_cmpint(2, >=, path_pos); + } else if(g_strcmp0(l->data, "/prebar/") == 0) { + g_assert_cmpint(2, >=, path_pos); + } else if(g_strcmp0(l->data, "/postfoo/") == 0) { + g_assert_cmpint(2, <, path_pos); + } else if(g_strcmp0(l->data, "/postbar/") == 0) { + g_assert_cmpint(2, <, path_pos); + g_assert_cmpint(4, ==, found_paths); main(gint argc, gchar **argv)
@@ -256,9 +322,14 @@
"/plugins/paths/add_default_paths",
test_gplugin_manager_add_default_paths);
"/plugins/paths/add_app_paths",
test_gplugin_manager_add_app_paths);
+ "/plugins/paths/add_app_paths_via_environ", + test_gplugin_manager_add_app_paths_via_environ);