[gnome-software/wip/rancell/ubuntu-3-20-rebase: 22/62] Allow plugins to conflict with each other



commit 3fe1391c162e5be52fe6e9048abe97c1be9577cb
Author: Richard Hughes <richard hughsie com>
Date:   Thu Mar 24 20:14:39 2016 +0000

    Allow plugins to conflict with each other
    
    The plugin defining the conflict is prefered, and if mutual then the lower
    priority plugin is automatically disabled.

 src/gs-plugin-loader.c                 |   75 +++++++++++++++++++++++++++----
 src/gs-plugin.h                        |    6 ++-
 src/plugins/gs-plugin-ubuntu-reviews.c |   12 +++++
 3 files changed, 82 insertions(+), 11 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index a648a6a..27fdf7e 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -2984,7 +2984,9 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        gboolean ret;
        GModule *module;
        GsPluginGetNameFunc plugin_name = NULL;
-       GsPluginGetDepsFunc plugin_deps = NULL;
+       GsPluginGetDepsFunc order_after = NULL;
+       GsPluginGetDepsFunc order_before = NULL;
+       GsPluginGetDepsFunc plugin_conflicts = NULL;
        GsPlugin *plugin = NULL;
 
        module = g_module_open (filename, 0);
@@ -3005,9 +3007,15 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        }
 
        /* get plugins this plugin depends on */
-       (void) g_module_symbol (module,
-                               "gs_plugin_order_after",
-                               (gpointer *) &plugin_deps);
+       g_module_symbol (module,
+                        "gs_plugin_order_after",
+                        (gpointer *) &order_after);
+       g_module_symbol (module,
+                        "gs_plugin_order_before",
+                        (gpointer *) &order_before);
+       g_module_symbol (module,
+                        "gs_plugin_get_conflicts",
+                        (gpointer *) &plugin_conflicts);
 
        /* print what we know */
        plugin = g_slice_new0 (GsPlugin);
@@ -3015,7 +3023,9 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        plugin->module = module;
        plugin->pixbuf_size = 64;
        plugin->priority = 0.f;
-       plugin->deps = plugin_deps != NULL ? plugin_deps (plugin) : NULL;
+       plugin->order_after = order_after != NULL ? order_after (plugin) : NULL;
+       plugin->order_before = order_before != NULL ? order_before (plugin) : NULL;
+       plugin->conflicts = plugin_conflicts != NULL ? plugin_conflicts (plugin) : NULL;
        plugin->name = g_strdup (plugin_name ());
        plugin->locale = priv->locale;
        plugin->status_update_fn = gs_plugin_loader_status_update_cb;
@@ -3162,20 +3172,20 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
                changes = FALSE;
                for (i = 0; i < priv->plugins->len; i++) {
                        plugin = g_ptr_array_index (priv->plugins, i);
-                       if (plugin->deps == NULL)
+                       if (plugin->order_after == NULL)
                                continue;
-                       for (j = 0; plugin->deps[j] != NULL && !changes; j++) {
+                       for (j = 0; plugin->order_after[j] != NULL && !changes; j++) {
                                dep = gs_plugin_loader_find_plugin (plugin_loader,
-                                                                   plugin->deps[j]);
+                                                                   plugin->order_after[j]);
                                if (dep == NULL) {
                                        g_debug ("cannot find plugin '%s'",
-                                                plugin->deps[j]);
+                                                plugin->order_after[j]);
                                        continue;
                                }
                                if (!dep->enabled)
                                        continue;
                                if (plugin->priority <= dep->priority) {
-                                       g_debug ("%s [%.1f] requires %s [%.1f] "
+                                       g_debug ("%s [%.1f] to be ordered after %s [%.1f] "
                                                 "so promoting to [%.1f]",
                                                 plugin->name, plugin->priority,
                                                 dep->name, dep->priority,
@@ -3185,6 +3195,31 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
                                }
                        }
                }
+               for (i = 0; i < priv->plugins->len; i++) {
+                       plugin = g_ptr_array_index (priv->plugins, i);
+                       if (plugin->order_before == NULL)
+                               continue;
+                       for (j = 0; plugin->order_before[j] != NULL && !changes; j++) {
+                               dep = gs_plugin_loader_find_plugin (plugin_loader,
+                                                                   plugin->order_before[j]);
+                               if (dep == NULL) {
+                                       g_debug ("cannot find plugin '%s'",
+                                                plugin->order_before[j]);
+                                       continue;
+                               }
+                               if (!dep->enabled)
+                                       continue;
+                               if (plugin->priority <= dep->priority) {
+                                       g_debug ("%s [%.1f] to be ordered before %s [%.1f] "
+                                                "so promoting to [%.1f]",
+                                                plugin->name, plugin->priority,
+                                                dep->name, dep->priority,
+                                                dep->priority + dep_increment);
+                                       dep->priority = plugin->priority + dep_increment;
+                                       changes = TRUE;
+                               }
+                       }
+               }
 
                /* check we're not stuck */
                if (dep_loop_check++ > 100) {
@@ -3203,6 +3238,26 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
        /* run the plugins */
        gs_plugin_loader_run (plugin_loader, "gs_plugin_initialize");
 
+       /* check for conflicts */
+       for (i = 0; i < priv->plugins->len; i++) {
+               plugin = g_ptr_array_index (priv->plugins, i);
+               if (!plugin->enabled)
+                       continue;
+               if (plugin->conflicts == NULL)
+                       continue;
+               for (j = 0; plugin->conflicts[j] != NULL && !changes; j++) {
+                       dep = gs_plugin_loader_find_plugin (plugin_loader,
+                                                           plugin->conflicts[j]);
+                       if (dep == NULL)
+                               continue;
+                       if (!dep->enabled)
+                               continue;
+                       g_debug ("disabling %s as conflicts with %s",
+                                dep->name, plugin->name);
+                       dep->enabled = FALSE;
+               }
+       }
+
        /* now we can load the install-queue */
        if (!load_install_queue (plugin_loader, error))
                return FALSE;
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index f49d1eb..b6c18f8 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -64,7 +64,9 @@ typedef gboolean (*GsPluginListFilter)        (GsApp          *app,
 struct GsPlugin {
        GModule                 *module;
        gdouble                  priority;      /* largest number gets run first */
-       const gchar             **deps;         /* allow-none */
+       const gchar             **order_after;  /* allow-none */
+       const gchar             **order_before; /* allow-none */
+       const gchar             **conflicts;    /* allow-none */
        gboolean                 enabled;
        gchar                   *name;
        GsPluginPrivate         *priv;
@@ -219,6 +221,8 @@ gboolean     gs_plugin_add_search_what_provides     (GsPlugin       *plugin,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
 const gchar    **gs_plugin_order_after                 (GsPlugin       *plugin);
+const gchar    **gs_plugin_order_before                (GsPlugin       *plugin);
+const gchar    **gs_plugin_get_conflicts               (GsPlugin       *plugin);
 gboolean        gs_plugin_add_installed                (GsPlugin       *plugin,
                                                         GList          **list,
                                                         GCancellable   *cancellable,
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index 43c9ee5..16adcfd 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -84,6 +84,18 @@ gs_plugin_order_after (GsPlugin *plugin)
        return deps;
 }
 
+/**
+ * gs_plugin_get_conflicts:
+ */
+const gchar **
+gs_plugin_get_conflicts (GsPlugin *plugin)
+{
+       static const gchar *deps[] = {
+               "odrs",
+               NULL };
+       return deps;
+}
+
 void
 gs_plugin_destroy (GsPlugin *plugin)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]