[gnome-software/wip/iainl/ubuntu-xenial: 262/287] Allow plugins to conflict with each other



commit 3c6a38bfbe60b97142e608c740d39a253f525330
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                 |   25 +++++
 src/gs-plugin.h                        |    2 +
 src/plugins/gs-plugin-ostree.c         |  162 ++++++++++++++++++++++++++++++++
 src/plugins/gs-plugin-ubuntu-reviews.c |   12 +++
 4 files changed, 201 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 676767c..af37aa0 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -2985,6 +2985,7 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        GModule *module;
        GsPluginGetNameFunc plugin_name = NULL;
        GsPluginGetDepsFunc plugin_deps = NULL;
+       GsPluginGetDepsFunc plugin_conflicts = NULL;
        GsPlugin *plugin = NULL;
 
        module = g_module_open (filename, 0);
@@ -3008,6 +3009,9 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        (void) g_module_symbol (module,
                                "gs_plugin_get_deps",
                                (gpointer *) &plugin_deps);
+       g_module_symbol (module,
+                        "gs_plugin_get_conflicts",
+                        (gpointer *) &plugin_conflicts);
 
        /* print what we know */
        plugin = g_slice_new0 (GsPlugin);
@@ -3016,6 +3020,7 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        plugin->pixbuf_size = 64;
        plugin->priority = 0.f;
        plugin->deps = plugin_deps != NULL ? plugin_deps (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;
@@ -3203,6 +3208,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 3ed167d..57526b2 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -65,6 +65,7 @@ struct GsPlugin {
        GModule                 *module;
        gdouble                  priority;      /* largest number gets run first */
        const gchar             **deps;         /* allow-none */
+       const gchar             **conflicts;    /* allow-none */
        gboolean                 enabled;
        gchar                   *name;
        GsPluginPrivate         *priv;
@@ -214,6 +215,7 @@ gboolean     gs_plugin_add_search_what_provides     (GsPlugin       *plugin,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
 const gchar    **gs_plugin_get_deps                    (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-ostree.c b/src/plugins/gs-plugin-ostree.c
new file mode 100644
index 0000000..b923733
--- /dev/null
+++ b/src/plugins/gs-plugin-ostree.c
@@ -0,0 +1,162 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2016 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <ostree.h>
+#include <gio/gio.h>
+#include <glib/gstdio.h>
+
+#include <gs-plugin.h>
+
+#include "gs-utils.h"
+
+struct GsPluginPrivate {
+       OstreeRepo              *ostree_repo;
+};
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+       return "ostree";
+}
+
+/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+       plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+
+       /* only works on OSTree */
+       if (!g_file_test ("/run/ostree-booted", G_FILE_TEST_EXISTS)) {
+               gs_plugin_set_enabled (plugin, FALSE);
+               return;
+       }
+}
+
+/**
+ * gs_plugin_get_conflicts:
+ */
+const gchar **
+gs_plugin_get_conflicts (GsPlugin *plugin)
+{
+       static const gchar *deps[] = {
+               "packagekit",
+               "packagekit-history",
+               "packagekit-offline",
+               "packagekit-origin",
+               "packagekit-proxy",
+               "packagekit-refine",
+               "packagekit-refresh",
+               "systemd-updates",
+               NULL };
+       return deps;
+}
+
+/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+       if (plugin->priv->ostree_repo != NULL)
+               g_object_unref (plugin->priv->ostree_repo);
+}
+
+/**
+ * gs_plugin_startup:
+ */
+static gboolean
+gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
+{
+       /* already started */
+       if (plugin->priv->ostree_repo != NULL)
+               return TRUE;
+
+       /* open */
+       plugin->priv->ostree_repo = ostree_repo_new_default ();
+       if (!ostree_repo_open (plugin->priv->ostree_repo, cancellable, error))
+               return FALSE;
+       return TRUE;
+}
+
+/**
+ * gs_plugin_add_sources:
+ */
+gboolean
+gs_plugin_add_sources (GsPlugin *plugin,
+                      GList **list,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       guint i;
+       g_auto(GStrv) names = NULL;
+
+       /* set up plugin */
+       if (!gs_plugin_startup (plugin, cancellable, error))
+               return FALSE;
+
+       /* get all remotes */
+       names = ostree_repo_remote_list (plugin->priv->ostree_repo, NULL);
+       if (names == NULL)
+               return TRUE;
+       for (i = 0; names[i] != NULL; i++) {
+               g_autofree gchar *url = NULL;
+               g_autoptr(GsApp) app = NULL;
+
+               /* get info */
+               if (!ostree_repo_remote_get_url (plugin->priv->ostree_repo,
+                                                names[i], &url, error))
+                       return FALSE;
+
+               /* create app */
+               app = gs_app_new (names[i]);
+               gs_app_set_management_plugin (app, "ostree");
+               gs_app_set_kind (app, AS_APP_KIND_SOURCE);
+               gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+               gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, url);
+               gs_app_set_name (app, GS_APP_QUALITY_LOWEST, names[i]);
+       }
+
+       return TRUE;
+}
+
+/**
+ * gs_plugin_refresh:
+ */
+gboolean
+gs_plugin_refresh (GsPlugin *plugin,
+                  guint cache_age,
+                  GsPluginRefreshFlags flags,
+                  GCancellable *cancellable,
+                  GError **error)
+{
+       /* set up plugin */
+       if (!gs_plugin_startup (plugin, cancellable, error))
+               return FALSE;
+
+       return TRUE;
+}
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index d19e51e..477b2af 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -92,6 +92,18 @@ gs_plugin_get_deps (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]