[gnome-software] Do not assume 'in AppStream' means 'is available'



commit 1b5de0ced0a50a3366dc4505be4e722551bc67da
Author: Richard Hughes <richard hughsie com>
Date:   Wed Mar 15 15:33:50 2017 +0000

    Do not assume 'in AppStream' means 'is available'
    
    For PackageKit repos that are enabled_metadata=1 but enabled=0 we want to find
    the application, but to install it also means the source needs enabling.
    
    This fix just makes the code match the comment and tightens up the condition
    for setting the GsApp state from the existing AsApp state. The rest of the
    commit is just fixing up the self tests with the new assumptions.

 plugins/core/gs-appstream.c     |    2 +-
 plugins/dummy/gs-plugin-dummy.c |   52 ++++++++++++++++++++++++++++++++++++--
 plugins/flatpak/gs-flatpak.c    |    7 +++++
 plugins/modalias/Makefile.am    |    3 +-
 plugins/modalias/gs-self-test.c |    3 ++
 5 files changed, 62 insertions(+), 5 deletions(-)
---
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index 673f626..d0980f8 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -561,7 +561,7 @@ gs_appstream_refine_app (GsPlugin *plugin,
 
        /* is installed already */
        if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN &&
-           as_app_get_state (item) != AS_APP_STATE_UNKNOWN) {
+           as_app_get_state (item) == AS_APP_STATE_INSTALLED) {
                gs_app_set_state (app, as_app_get_state (item));
        }
 
diff --git a/plugins/dummy/gs-plugin-dummy.c b/plugins/dummy/gs-plugin-dummy.c
index 6d497da..73f5929 100644
--- a/plugins/dummy/gs-plugin-dummy.c
+++ b/plugins/dummy/gs-plugin-dummy.c
@@ -35,6 +35,8 @@ struct GsPluginData {
        guint                    has_auth;
        GsAuth                  *auth;
        GsApp                   *cached_origin;
+       GHashTable              *installed_apps;        /* id:1 */
+       GHashTable              *available_apps;        /* id:1 */
 };
 
 /* just flip-flop this every few seconds */
@@ -86,6 +88,19 @@ gs_plugin_initialize (GsPlugin *plugin)
         * unique ID to a GsApp when creating an event */
        gs_plugin_cache_add (plugin, NULL, priv->cached_origin);
 
+       /* keep track of what apps are installed */
+       priv->installed_apps = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+       priv->available_apps = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+       g_hash_table_insert (priv->available_apps,
+                            g_strdup ("zeus.desktop"),
+                            GUINT_TO_POINTER (1));
+       g_hash_table_insert (priv->available_apps,
+                            g_strdup ("zeus-spell.addon"),
+                            GUINT_TO_POINTER (1));
+       g_hash_table_insert (priv->available_apps,
+                            g_strdup ("com.hughski.ColorHug2.driver"),
+                            GUINT_TO_POINTER (1));
+
        /* need help from appstream */
        gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
        gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "odrs");
@@ -95,6 +110,10 @@ void
 gs_plugin_destroy (GsPlugin *plugin)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
+       if (priv->installed_apps != NULL)
+               g_hash_table_unref (priv->installed_apps);
+       if (priv->available_apps != NULL)
+               g_hash_table_unref (priv->available_apps);
        if (priv->quirk_id > 0)
                g_source_remove (priv->quirk_id);
        if (priv->auth != NULL)
@@ -417,6 +436,8 @@ gs_plugin_app_remove (GsPlugin *plugin,
                      GCancellable *cancellable,
                      GError **error)
 {
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+
        /* only process this app if was created by this plugin */
        if (g_strcmp0 (gs_app_get_management_plugin (app),
                       gs_plugin_get_name (plugin)) != 0)
@@ -431,6 +452,12 @@ gs_plugin_app_remove (GsPlugin *plugin,
                }
                gs_app_set_state (app, AS_APP_STATE_UNKNOWN);
        }
+
+       /* keep track */
+       g_hash_table_remove (priv->installed_apps, gs_app_get_id (app));
+       g_hash_table_insert (priv->available_apps,
+                            g_strdup (gs_app_get_id (app)),
+                            GUINT_TO_POINTER (1));
        return TRUE;
 }
 
@@ -440,6 +467,8 @@ gs_plugin_app_install (GsPlugin *plugin,
                       GCancellable *cancellable,
                       GError **error)
 {
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+
        /* only process this app if was created by this plugin */
        if (g_strcmp0 (gs_app_get_management_plugin (app),
                       gs_plugin_get_name (plugin)) != 0)
@@ -454,6 +483,13 @@ gs_plugin_app_install (GsPlugin *plugin,
                }
                gs_app_set_state (app, AS_APP_STATE_INSTALLED);
        }
+
+       /* keep track */
+       g_hash_table_insert (priv->installed_apps,
+                            g_strdup (gs_app_get_id (app)),
+                            GUINT_TO_POINTER (1));
+       g_hash_table_remove (priv->available_apps, gs_app_get_id (app));
+
        return TRUE;
 }
 
@@ -498,13 +534,23 @@ gs_plugin_refine_app (GsPlugin *plugin,
                      GCancellable *cancellable,
                      GError **error)
 {
-       /* default */
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+
+       /* state */
+       if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN) {
+               if (g_hash_table_lookup (priv->installed_apps,
+                                        gs_app_get_id (app)) != NULL)
+                       gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+               if (g_hash_table_lookup (priv->available_apps,
+                                        gs_app_get_id (app)) != NULL)
+                       gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
+       }
+
+       /* kind */
        if (g_strcmp0 (gs_app_get_id (app), "chiron.desktop") == 0 ||
            g_strcmp0 (gs_app_get_id (app), "mate-spell.desktop") == 0 ||
            g_strcmp0 (gs_app_get_id (app), "com.hughski.ColorHug2.driver") == 0 ||
            g_strcmp0 (gs_app_get_id (app), "zeus.desktop") == 0) {
-               if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN)
-                       gs_app_set_state (app, AS_APP_STATE_INSTALLED);
                if (gs_app_get_kind (app) == AS_APP_KIND_UNKNOWN)
                        gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
        }
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index fdceb84..0c14954 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2053,6 +2053,7 @@ gs_flatpak_refine_app (GsFlatpak *self,
                       GCancellable *cancellable,
                       GError **error)
 {
+       AsAppState old_state = gs_app_get_state (app);
        g_autoptr(AsProfileTask) ptask = NULL;
 
        /* profile */
@@ -2084,6 +2085,12 @@ gs_flatpak_refine_app (GsFlatpak *self,
                return FALSE;
        }
 
+       /* if the state was changed, perhaps set the version from the release */
+       if (old_state != gs_app_get_state (app)) {
+               if (!gs_flatpak_refine_appstream (self, app, error))
+                       return FALSE;
+       }
+
        /* version fallback */
        if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION) {
                if (gs_app_get_version (app) == NULL) {
diff --git a/plugins/modalias/Makefile.am b/plugins/modalias/Makefile.am
index fb14092..ba9a663 100644
--- a/plugins/modalias/Makefile.am
+++ b/plugins/modalias/Makefile.am
@@ -2,7 +2,8 @@ AM_CPPFLAGS =                                           \
        -DG_LOG_DOMAIN=\"GsPluginModalias\"             \
        -DTESTDATADIR=\""$(srcdir)/tests"\"             \
        -DLOCALPLUGINDIR=\""$(builddir)/.libs"\"        \
-       -DLOCALPLUGINDIR_CORE=\""$(top_builddir)/plugins/core/.libs"\"
+       -DLOCALPLUGINDIR_CORE=\""$(top_builddir)/plugins/core/.libs"\"\
+       -DLOCALPLUGINDIR_DUMMY=\""$(top_builddir)/plugins/dummy/.libs"\"
 
 plugindir = $(GS_PLUGIN_DIR)
 plugin_LTLIBRARIES = libgs_plugin_modalias.la
diff --git a/plugins/modalias/gs-self-test.c b/plugins/modalias/gs-self-test.c
index 590b7c5..3c9adb9 100644
--- a/plugins/modalias/gs-self-test.c
+++ b/plugins/modalias/gs-self-test.c
@@ -62,12 +62,14 @@ main (int argc, char **argv)
        g_autoptr(GsPluginLoader) plugin_loader = NULL;
        const gchar *whitelist[] = {
                "appstream",
+               "dummy",
                "modalias",
                NULL
        };
 
        g_test_init (&argc, &argv, NULL);
        g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
+       g_setenv ("GS_SELF_TEST_DUMMY_ENABLE", "1", TRUE);
 
        xml = g_strdup_printf ("<?xml version=\"1.0\"?>\n"
                "<components version=\"0.9\">\n"
@@ -89,6 +91,7 @@ main (int argc, char **argv)
        plugin_loader = gs_plugin_loader_new ();
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR_CORE);
+       gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR_DUMMY);
        ret = gs_plugin_loader_setup (plugin_loader,
                                      (gchar**) whitelist,
                                      NULL,


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