[gnome-software] flatpak: Correctly find already installed runtimes



commit e34afa575b7bb256d14c98b91a3e23206e9faa5e
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jul 13 17:14:00 2017 +0100

    flatpak: Correctly find already installed runtimes
    
    Never try to change an INSTALLED app to LOCAL when using a flatpakref and
    do not use GsFlatpakApp fields for an AppStream-created runtime.

 plugins/flatpak/gs-flatpak.c        |   37 ++++++++++++++++++++++++++--------
 plugins/flatpak/gs-flatpak.h        |    5 ++-
 plugins/flatpak/gs-plugin-flatpak.c |   24 +++++++++++++++-------
 plugins/flatpak/gs-self-test.c      |   14 +++++++++++++
 4 files changed, 61 insertions(+), 19 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 411de16..273177d 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -890,6 +890,9 @@ gs_flatpak_find_source_by_url (GsFlatpak *self,
                               GError **error)
 {
        g_autoptr(GPtrArray) xremotes = NULL;
+
+       g_return_val_if_fail (url != NULL, FALSE);
+
        xremotes = flatpak_installation_list_remotes (self->installation, cancellable, error);
        if (xremotes == NULL)
                return FALSE;
@@ -905,14 +908,18 @@ gs_flatpak_find_source_by_url (GsFlatpak *self,
 }
 
 gboolean
-gs_flatpak_find_app_by_ref_display (GsFlatpak *self,
-                               const gchar *ref_display,
-                               GsAppList *list,
-                               GCancellable *cancellable,
-                               GError **error)
+gs_flatpak_find_app_by_name_branch (GsFlatpak *self,
+                                   const gchar *name,
+                                   const gchar *branch,
+                                   GsAppList *list,
+                                   GCancellable *cancellable,
+                                   GError **error)
 {
        g_autoptr(GPtrArray) xrefs = NULL;
 
+       g_return_val_if_fail (name != NULL, FALSE);
+       g_return_val_if_fail (branch != NULL, FALSE);
+
        /* get all the installed apps (no network I/O) */
        xrefs = flatpak_installation_list_installed_refs (self->installation,
                                                          cancellable,
@@ -924,10 +931,12 @@ gs_flatpak_find_app_by_ref_display (GsFlatpak *self,
 
        /* look at each installed xref */
        for (guint i = 0; i < xrefs->len; i++) {
-               FlatpakRef *xref = g_ptr_array_index (xrefs, i);
-               g_autofree gchar *ref_tmp = flatpak_ref_format_ref (xref);
-               if (g_strcmp0 (ref_tmp, ref_display) == 0) {
-                       g_autoptr(GsApp) app = gs_flatpak_create_app (self, xref);
+               FlatpakInstalledRef *xref = g_ptr_array_index (xrefs, i);
+               if (g_strcmp0 (flatpak_ref_get_name (FLATPAK_REF (xref)), name) == 0 &&
+                   g_strcmp0 (flatpak_ref_get_branch (FLATPAK_REF (xref)), branch) == 0) {
+                       g_autoptr(GsApp) app = gs_flatpak_create_installed (self, xref, error);
+                       if (app == NULL)
+                               return FALSE;
                        gs_app_list_add (list, app);
                }
        }
@@ -2847,6 +2856,11 @@ gs_flatpak_file_to_app_bundle (GsFlatpak *self,
 
        /* load metadata */
        app = gs_flatpak_create_app (self, FLATPAK_REF (xref_bundle));
+       if (gs_app_get_state (app) == AS_APP_STATE_INSTALLED) {
+               if (gs_flatpak_app_get_ref_name (app) == NULL)
+                       gs_flatpak_set_metadata (self, app, FLATPAK_REF (xref_bundle));
+               return g_steal_pointer (&app);
+       }
        gs_flatpak_app_set_file_kind (app, GS_FLATPAK_APP_FILE_KIND_BUNDLE);
        gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
        gs_app_set_state (app, AS_APP_STATE_AVAILABLE_LOCAL);
@@ -3040,6 +3054,11 @@ gs_flatpak_file_to_app_ref (GsFlatpak *self,
 
        /* load metadata */
        app = gs_flatpak_create_app (self, FLATPAK_REF (xref));
+       if (gs_app_get_state (app) == AS_APP_STATE_INSTALLED) {
+               if (gs_flatpak_app_get_ref_name (app) == NULL)
+                       gs_flatpak_set_metadata (self, app, FLATPAK_REF (xref));
+               return g_steal_pointer (&app);
+       }
        gs_app_add_quirk (app, AS_APP_QUIRK_HAS_SOURCE);
        gs_flatpak_app_set_file_kind (app, GS_FLATPAK_APP_FILE_KIND_REF);
        gs_app_set_state (app, AS_APP_STATE_AVAILABLE_LOCAL);
diff --git a/plugins/flatpak/gs-flatpak.h b/plugins/flatpak/gs-flatpak.h
index a68ba7a..5b60a3e 100644
--- a/plugins/flatpak/gs-flatpak.h
+++ b/plugins/flatpak/gs-flatpak.h
@@ -108,8 +108,9 @@ gboolean     gs_flatpak_find_source_by_url  (GsFlatpak              *self,
                                                 GsAppList              *list,
                                                 GCancellable           *cancellable,
                                                 GError                 **error);
-gboolean        gs_flatpak_find_app_by_ref_display     (GsFlatpak              *self,
-                                                const gchar            *ref_display,
+gboolean        gs_flatpak_find_app_by_name_branch (GsFlatpak          *self,
+                                                const gchar            *id,
+                                                const gchar            *branch,
                                                 GsAppList              *list,
                                                 GCancellable           *cancellable,
                                                 GError                 **error);
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index b7f3ae2..3a5efd5 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -512,8 +512,9 @@ gs_plugin_flatpak_file_to_app_bundle (GsPlugin *plugin,
        list_tmp = gs_app_list_new ();
        for (guint i = 0; i < priv->flatpaks->len; i++) {
                GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
-               if (!gs_flatpak_find_app_by_ref_display (flatpak,
-                                                        gs_flatpak_app_get_ref_display (app_tmp),
+               if (!gs_flatpak_find_app_by_name_branch (flatpak,
+                                                        gs_flatpak_app_get_ref_name (app_tmp),
+                                                        gs_flatpak_app_get_ref_branch (app_tmp),
                                                         list_tmp, cancellable, error))
                        return FALSE;
        }
@@ -564,8 +565,9 @@ gs_plugin_flatpak_file_to_app_ref (GsPlugin *plugin,
        list_tmp = gs_app_list_new ();
        for (guint i = 0; i < priv->flatpaks->len; i++) {
                GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
-               if (!gs_flatpak_find_app_by_ref_display (flatpak,
-                                                        gs_flatpak_app_get_ref_display (app_tmp),
+               if (!gs_flatpak_find_app_by_name_branch (flatpak,
+                                                        gs_flatpak_app_get_ref_name (app_tmp),
+                                                        gs_flatpak_app_get_ref_branch (app_tmp),
                                                         list_tmp, cancellable, error))
                        return FALSE;
        }
@@ -592,8 +594,13 @@ gs_plugin_flatpak_file_to_app_ref (GsPlugin *plugin,
                        GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
                        if (gs_flatpak_get_scope (flatpak) != AS_APP_SCOPE_SYSTEM)
                                continue;
-                       if (!gs_flatpak_find_app_by_ref_display (flatpak,
-                                                                gs_flatpak_app_get_ref_display (runtime_app),
+                       g_debug ("looking for %s//%s in %s",
+                                gs_flatpak_app_get_ref_name (runtime_app),
+                                gs_flatpak_app_get_ref_branch (runtime_app),
+                                gs_flatpak_get_id (flatpak));
+                       if (!gs_flatpak_find_app_by_name_branch (flatpak,
+                                                                gs_flatpak_app_get_ref_name (runtime_app),
+                                                                gs_flatpak_app_get_ref_branch (runtime_app),
                                                                 list_system_runtimes,
                                                                 cancellable, error))
                                return FALSE;
@@ -601,11 +608,12 @@ gs_plugin_flatpak_file_to_app_ref (GsPlugin *plugin,
                for (guint i = 0; i < gs_app_list_length (list_system_runtimes); i++) {
                        GsApp *runtime_old = gs_app_list_index (list_system_runtimes, i);
                        if (gs_app_get_state (runtime_old) == AS_APP_STATE_INSTALLED) {
-                               g_error ("already have %s, using instead of %s",
+                               g_debug ("already have %s, using instead of %s",
                                         gs_app_get_unique_id (runtime_old),
                                         gs_app_get_unique_id (runtime_app));
                                gs_app_set_runtime (app_tmp, runtime_old);
-                               break;;
+                               gs_app_set_update_runtime (app_tmp, runtime_old);
+                               break;
                        }
                }
        }
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index 40d7c23..5af23ee 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -870,6 +870,20 @@ gs_plugins_flatpak_ref_func (GsPluginLoader *plugin_loader)
        app_tmp = gs_app_list_index (search1, 0);
        g_assert_cmpstr (gs_app_get_id (app_tmp), ==, "org.test.Chiron.desktop");
 
+       /* convert it to a GsApp again, and get the installed thing */
+       g_object_unref (plugin_job);
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_FILE_TO_APP,
+                                        "file", file,
+                                        "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION |
+                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_RUNTIME,
+                                        NULL);
+       app = gs_plugin_loader_job_process_app (plugin_loader, plugin_job, NULL, &error);
+       g_assert_no_error (error);
+       g_assert (app != NULL);
+       g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
+       g_assert (as_utils_unique_id_equal (gs_app_get_unique_id (app),
+                 "user/flatpak/org.test.Chiron-origin/desktop/org.test.Chiron.desktop/master"));
+
        /* remove app */
        g_object_unref (plugin_job);
        plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,


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