[gnome-software] Treat install-bundles-system-wide as advisory, rather than policy



commit 2ae5c0a2c0b509fc3173e0186c4be774c0b00e84
Author: Richard Hughes <richard hughsie com>
Date:   Tue Nov 15 18:57:52 2016 +0000

    Treat install-bundles-system-wide as advisory, rather than policy
    
    If we can't use the system flatpak plugin due to permissions then fall back to
    the user plugin and treat the GSetting as best effort, rather than system
    policy.
    
    This is implemented by just raising the priority ordering of one of the plugins
    above the over and then ignoring the request if a GsApp has already been added.

 src/plugins/gs-plugin-flatpak-system.c |   16 +++++++++-------
 src/plugins/gs-plugin-flatpak-user.c   |   18 ++++++++++--------
 2 files changed, 19 insertions(+), 15 deletions(-)
---
diff --git a/src/plugins/gs-plugin-flatpak-system.c b/src/plugins/gs-plugin-flatpak-system.c
index 9da8394..9041993 100644
--- a/src/plugins/gs-plugin-flatpak-system.c
+++ b/src/plugins/gs-plugin-flatpak-system.c
@@ -36,15 +36,15 @@
 
 struct GsPluginData {
        GsFlatpak               *flatpak;
-       GSettings               *settings;
 };
 
 void
 gs_plugin_initialize (GsPlugin *plugin)
 {
        GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+       g_autoptr(GSettings) settings = g_settings_new ("org.gnome.software");
+
        priv->flatpak = gs_flatpak_new (plugin, AS_APP_SCOPE_SYSTEM);
-       priv->settings = g_settings_new ("org.gnome.software");
 
        /* set plugin flags */
        gs_plugin_add_flags (plugin, GS_PLUGIN_FLAGS_GLOBAL_CACHE);
@@ -54,6 +54,10 @@ gs_plugin_initialize (GsPlugin *plugin)
 
        /* prioritize over packages */
        gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_BETTER_THAN, "packagekit");
+
+       /* prefer system-wide handling of local files */
+       if (g_settings_get_boolean (settings, "install-bundles-system-wide"))
+               gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "flatpak-user");
 }
 
 void
@@ -61,7 +65,6 @@ gs_plugin_destroy (GsPlugin *plugin)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
        g_clear_object (&priv->flatpak);
-       g_clear_object (&priv->settings);
 }
 
 void
@@ -224,10 +227,9 @@ gs_plugin_file_to_app (GsPlugin *plugin,
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
 
-       /* only handle when installing bundles system-wide */
-       if (!g_settings_get_boolean (priv->settings,
-                                    "install-bundles-system-wide")) {
-               g_debug ("not handling bundle as per-user specified");
+       /* only handle when nothing yet has added this */
+       if (gs_app_list_length (list) > 0) {
+               g_debug ("not handling bundle as already added");
                return TRUE;
        }
 
diff --git a/src/plugins/gs-plugin-flatpak-user.c b/src/plugins/gs-plugin-flatpak-user.c
index 6080fd6..2394cd2 100644
--- a/src/plugins/gs-plugin-flatpak-user.c
+++ b/src/plugins/gs-plugin-flatpak-user.c
@@ -36,15 +36,15 @@
 
 struct GsPluginData {
        GsFlatpak               *flatpak;
-       GSettings               *settings;
 };
 
 void
 gs_plugin_initialize (GsPlugin *plugin)
 {
        GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+       g_autoptr(GSettings) settings = g_settings_new ("org.gnome.software");
+
        priv->flatpak = gs_flatpak_new (plugin, AS_APP_SCOPE_USER);
-       priv->settings = g_settings_new ("org.gnome.software");
 
        /* set plugin flags */
        gs_plugin_add_flags (plugin, GS_PLUGIN_FLAGS_GLOBAL_CACHE);
@@ -54,14 +54,18 @@ gs_plugin_initialize (GsPlugin *plugin)
 
        /* prioritize over packages */
        gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_BETTER_THAN, "packagekit");
+
+       /* prefer user-specific handling of local files */
+       if (!g_settings_get_boolean (settings, "install-bundles-system-wide"))
+               gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "flatpak-system");
 }
 
+
 void
 gs_plugin_destroy (GsPlugin *plugin)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
        g_clear_object (&priv->flatpak);
-       g_clear_object (&priv->settings);
 }
 
 void
@@ -207,11 +211,9 @@ gs_plugin_file_to_app (GsPlugin *plugin,
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
 
-       /* only handle when installing bundles user-wide */
-       if (g_getenv ("GS_SELF_TEST_FLATPACK_DATADIR") == NULL &&
-           g_settings_get_boolean (priv->settings,
-                                   "install-bundles-system-wide")) {
-               g_debug ("not handling bundle as per-system specified");
+       /* only handle when nothing yet has added this */
+       if (gs_app_list_length (list) > 0) {
+               g_debug ("not handling bundle as already added");
                return TRUE;
        }
 


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