[gnome-software/wip/hughsie/unique_id] f



commit b27c2340470494cebab67d88969f29add44088f8
Author: Richard Hughes <richard hughsie com>
Date:   Fri Jul 29 15:50:17 2016 +0100

    f

 src/gs-app.c                           |   15 +++-------
 src/gs-plugin-loader.c                 |   14 +++++-----
 src/gs-self-test.c                     |    6 +---
 src/plugins/gs-appstream.c             |   13 +++++---
 src/plugins/gs-flatpak.c               |   32 +++++++++++++++------
 src/plugins/gs-plugin-appstream.c      |   47 ++++++++++++++++++-------------
 src/plugins/gs-plugin-flatpak-system.c |    2 +-
 src/plugins/gs-plugin-flatpak-user.c   |    2 +-
 8 files changed, 74 insertions(+), 57 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index aabfe7c..ffda463 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -508,19 +508,14 @@ gs_app_get_id (GsApp *app)
 void
 gs_app_set_id (GsApp *app, const gchar *id)
 {
-       gchar *tmp;
        g_return_if_fail (GS_IS_APP (app));
 
        /* check for old-style prefix */
-       if (id != NULL) {
-               tmp = g_strrstr (id, ":");
-               if (tmp != NULL) {
-                       g_debug ("FIXME: Fixing up %s legacy ID, use "
-                                "gs_app_set_unique_id() and use the actual "
-                                "desktop-style ID here instead!", id);
-                       gs_app_set_unique_id (app, id);
-                       id = tmp + 1;
-               }
+       if (id != NULL && g_strstr_len (id, -1, ":") != NULL) {
+               g_warning ("Invalid ID of %s -- use "
+                          "gs_app_set_unique_id() and use the actual "
+                          "desktop-style ID here instead!", id);
+               return;
        }
 
        g_free (app->id);
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index d808bce..25c3ba0 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -260,7 +260,7 @@ gs_plugin_loader_run_adopt (GsPluginLoader *plugin_loader, GsAppList *list)
                        if (gs_app_get_management_plugin (app) != NULL) {
                                g_debug ("%s adopted %s",
                                         gs_plugin_get_name (plugin),
-                                        gs_app_get_id (app));
+                                        gs_app_get_unique_id (app));
                        }
                }
        }
@@ -665,7 +665,7 @@ gs_plugin_loader_get_app_str (GsApp *app)
        const gchar *id;
 
        /* first try the actual id */
-       id = gs_app_get_id (app);
+       id = gs_app_get_unique_id (app);
        if (id != NULL)
                return id;
 
@@ -883,12 +883,12 @@ gs_plugin_loader_set_app_error (GsApp *app, GError *error)
        /* random, non-plugin error domains are never shown to the user */
        if (error->domain == GS_PLUGIN_ERROR) {
                g_debug ("saving error for %s: %s",
-                        gs_app_get_id (app),
+                        gs_app_get_unique_id (app),
                         error->message);
                gs_app_set_last_error (app, error);
        } else {
                g_warning ("not saving error for %s: %s",
-                          gs_app_get_id (app),
+                          gs_app_get_unique_id (app),
                           error->message);
        }
 }
@@ -2727,7 +2727,7 @@ gs_plugin_loader_app_action_thread_cb (GTask *task,
        case AS_APP_STATE_INSTALLING:
        case AS_APP_STATE_REMOVING:
                g_warning ("application %s left in %s state",
-                          gs_app_get_id (state->app),
+                          gs_app_get_unique_id (state->app),
                           as_app_state_to_string (gs_app_get_state (state->app)));
                gs_app_set_state (state->app, AS_APP_STATE_UNKNOWN);
                break;
@@ -2867,7 +2867,7 @@ load_install_queue (GsPluginLoader *plugin_loader, GError **error)
                                 g_object_ref (app));
                g_mutex_unlock (&priv->pending_apps_mutex);
 
-               g_debug ("adding pending app %s", gs_app_get_id (app));
+               g_debug ("adding pending app %s", gs_app_get_unique_id (app));
                gs_app_list_add (list, app);
        }
 
@@ -3970,7 +3970,7 @@ gs_plugin_loader_app_installed_cb (GObject *source,
        if (!ret) {
                remove_app_from_install_queue (plugin_loader, app);
                g_warning ("failed to install %s: %s",
-                          gs_app_get_id (app), error->message);
+                          gs_app_get_unique_id (app), error->message);
        }
 }
 
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index f5f9e43..a44aa76 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -178,11 +178,9 @@ gs_app_func (void)
 {
        g_autoptr(GsApp) app = NULL;
 
-       app = gs_app_new ("flatpak:gnome-software");
+       app = gs_app_new ("gnome-software.desktop");
        g_assert (GS_IS_APP (app));
-
-       g_assert_cmpstr (gs_app_get_id (app), ==, "gnome-software");
-       g_assert_cmpstr (gs_app_get_unique_id (app), ==, "flatpak:gnome-software");
+       g_assert_cmpstr (gs_app_get_id (app), ==, "gnome-software.desktop");
 
        /* check we clean up the version, but not at the expense of having
         * the same string as the update version */
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 937decf..e5ade4b 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -511,6 +511,10 @@ gs_appstream_refine_app (GsPlugin *plugin,
        if (as_app_get_id (item) != NULL && gs_app_get_id (app) == NULL)
                gs_app_set_id (app, as_app_get_id (item));
 
+       /* set unique-id */
+       if (as_app_get_unique_id (item) != NULL && gs_app_get_unique_id (app) == NULL)
+               gs_app_set_unique_id (app, as_app_get_unique_id (item));
+
        /* set source */
        gs_app_set_metadata (app, "appstream::source-file", as_app_get_source_file (item));
 
@@ -555,11 +559,10 @@ gs_appstream_refine_app (GsPlugin *plugin,
        /* set origin */
        if (as_app_get_origin (item) != NULL &&
            gs_app_get_origin (app) == NULL ) {
-               tmp = as_app_get_origin (item);
-               if (g_str_has_prefix (tmp, "flatpak:"))
-                       gs_app_set_origin (app, tmp + 8);
-               if (g_str_has_prefix (tmp, "user-flatpak:"))
-                       gs_app_set_origin (app, tmp + 13);
+               tmp = as_app_get_unique_id (item);
+               if (g_str_has_prefix (tmp, "user/flatpak/") ||
+                   g_str_has_prefix (tmp, "system/flatpak/"))
+                       gs_app_set_origin (app, tmp);
        }
 
        /* set description */
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 88b67b3..cc82a35 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -218,15 +218,21 @@ gs_flatpak_refresh_appstream (GsFlatpak *self, guint cache_age,
        return TRUE;
 }
 
+static const gchar *
+_flatpak_ref_kind_to_string (FlatpakRefKind kind)
+{
+       if (kind == FLATPAK_REF_KIND_APP)
+               return "app";
+       if (kind == FLATPAK_REF_KIND_RUNTIME)
+               return "runtime";
+       return NULL;
+}
+
 static void
 gs_app_set_flatpak_kind (GsApp *app, FlatpakRefKind kind)
 {
-       if (kind == FLATPAK_REF_KIND_APP)
-               gs_app_set_metadata (app, "flatpak::kind", "app");
-       else if (kind == FLATPAK_REF_KIND_RUNTIME)
-               gs_app_set_metadata (app, "flatpak::kind", "runtime");
-       else
-               g_assert_not_reached ();
+       gs_app_set_metadata (app, "flatpak::kind",
+                            _flatpak_ref_kind_to_string (kind));
 }
 
 static void
@@ -296,16 +302,22 @@ gs_flatpak_build_id (FlatpakRef *xref)
 static gchar *
 gs_flatpak_build_unique_id (FlatpakInstallation *installation, FlatpakRef *xref)
 {
-       const gchar *prefix = GS_FLATPAK_SYSTEM_PREFIX;
+       const gchar *scope = "system";
        g_autofree gchar *id = NULL;
 
        /* use a different prefix if we're somehow running this as per-user */
        if (flatpak_installation_get_is_user (installation))
-               prefix = GS_FLATPAK_USER_PREFIX;
+               scope = "user";
 
        /* flatpak doesn't use a suffix; AppStream does */
        id = gs_flatpak_build_id (xref);
-       return g_strdup_printf ("%s:%s", prefix, id);
+       return as_utils_unique_id_build (scope,
+                                        "flatpak",
+                                        NULL, /* origin */
+                                        _flatpak_ref_kind_to_string (flatpak_ref_get_kind (xref)),
+                                        id,
+                                        flatpak_ref_get_arch (xref),
+                                        flatpak_ref_get_branch (xref));
 }
 
 static GsApp *
@@ -953,6 +965,8 @@ gs_flatpak_app_matches_xref (GsFlatpak *self, GsApp *app, FlatpakRef *xref)
                       flatpak_ref_get_branch (xref)) == 0)
                return TRUE;
 
+g_debug ("no match for %s == %s", id, gs_app_get_unique_id (app));
+
        /* sad panda */
        return FALSE;
 }
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 1f3f54e..265e202 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -305,23 +305,30 @@ gs_plugin_refine_from_id (GsPlugin *plugin,
                          GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
-       const gchar *id;
+       const gchar *unique_id;
        AsApp *item;
 
        /* unfound */
        *found = FALSE;
 
        /* find anything that matches the ID */
-       id = gs_app_get_id (app);
-       if (id == NULL)
+       unique_id = gs_app_get_unique_id (app);
+       if (unique_id == NULL)
                return TRUE;
 
        /* nothing found */
-       item = as_store_get_app_by_id (priv->store, gs_app_get_unique_id (app));
-       if (item == NULL)
-               item = as_store_get_app_by_id (priv->store, id);
-       if (item == NULL)
+g_warning ("loooking for %s", unique_id);
+       item = as_store_get_app_by_unique_id (priv->store, unique_id);
+       if (item == NULL) {
+               const gchar *id = gs_app_get_id (app);
+               g_warning ("loooking HARDER for %s", unique_id);
+               if (g_strcmp0 (unique_id, id) != 0)
+                       item = as_store_get_app_by_id (priv->store, id);
+       }
+       if (item == NULL) {
+               g_warning ("No app with ID %s found!", unique_id);
                return TRUE;
+       }
 
        /* set new properties */
        if (!gs_appstream_refine_app (plugin, app, item, error))
@@ -361,14 +368,16 @@ gs_plugin_refine_from_pkgname (GsPlugin *plugin,
 }
 
 static GsApp *
-gs_plugin_appstream_create_app (GsPlugin *plugin, const gchar *id)
+gs_plugin_appstream_create_app (GsPlugin *plugin, AsApp *item)
 {
-       GsApp *app = gs_plugin_cache_lookup (plugin, id);
+       const gchar *unique_id = as_app_get_unique_id (item);
+       GsApp *app = gs_plugin_cache_lookup (plugin, unique_id);
        if (app == NULL) {
-               app = gs_app_new (id);
+               app = gs_app_new (as_app_get_id (item));
+               gs_app_set_unique_id (app, unique_id);
                gs_app_set_metadata (app, "GnomeSoftware::Creator",
                                     gs_plugin_get_name (plugin));
-               gs_plugin_cache_add (plugin, id, app);
+               gs_plugin_cache_add (plugin, unique_id, app);
        }
        return app;
 }
@@ -393,7 +402,7 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
                        continue;
 
                /* create */
-               app = gs_plugin_appstream_create_app (plugin, as_app_get_id (item));
+               app = gs_plugin_appstream_create_app (plugin, item);
                gs_app_set_kind (app, AS_APP_KIND_OS_UPGRADE);
                gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
                if (!gs_appstream_refine_app (plugin, app, item, error))
@@ -462,8 +471,7 @@ gs_plugin_appstream_add_wildcards (GsPlugin *plugin,
                /* new app */
                g_debug ("found %s for wildcard %s",
                         as_app_get_id (item), id);
-               new = gs_plugin_appstream_create_app (plugin,
-                                                     as_app_get_id (item));
+               new = gs_plugin_appstream_create_app (plugin, item);
                if (!gs_appstream_refine_app (plugin, new, item, error))
                        return FALSE;
                gs_app_list_add (list, new);
@@ -556,8 +564,7 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
                                continue;
 
                        /* add all the data we can */
-                       app = gs_plugin_appstream_create_app (plugin,
-                                                             as_app_get_id (item));
+                       app = gs_plugin_appstream_create_app (plugin, item);
                        if (!gs_appstream_refine_app (plugin, app, item, error))
                                return FALSE;
                        gs_app_list_add (list, app);
@@ -593,7 +600,7 @@ gs_plugin_add_search_item (GsPlugin *plugin,
                return TRUE;
 
        /* create app */
-       app = gs_plugin_appstream_create_app (plugin, as_app_get_id (item));
+       app = gs_plugin_appstream_create_app (plugin, item);
        if (!gs_appstream_refine_app (plugin, app, item, error))
                return FALSE;
        gs_app_set_match_value (app, match_value);
@@ -653,7 +660,7 @@ gs_plugin_add_installed (GsPlugin *plugin,
                item = g_ptr_array_index (array, i);
                if (as_app_get_state (item) == AS_APP_STATE_INSTALLED) {
                        g_autoptr(GsApp) app = NULL;
-                       app = gs_plugin_appstream_create_app (plugin, as_app_get_id (item));
+                       app = gs_plugin_appstream_create_app (plugin, item);
                        if (!gs_appstream_refine_app (plugin, app, item, error))
                                return FALSE;
                        gs_app_list_add (list, app);
@@ -748,7 +755,7 @@ gs_plugin_add_popular (GsPlugin *plugin,
                        continue;
                if (!as_app_has_kudo (item, "GnomeSoftware::popular"))
                        continue;
-               app = gs_plugin_appstream_create_app (plugin, as_app_get_id_no_prefix (item));
+               app = gs_plugin_appstream_create_app (plugin, item);
                gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
                gs_app_list_add (list, app);
        }
@@ -779,7 +786,7 @@ gs_plugin_add_featured (GsPlugin *plugin,
                        continue;
                if (as_app_get_metadata_item (item, "GnomeSoftware::FeatureTile-css") == NULL)
                        continue;
-               app = gs_plugin_appstream_create_app (plugin, as_app_get_id_no_prefix (item));
+               app = gs_plugin_appstream_create_app (plugin, item);
                if (!gs_appstream_refine_app (plugin, app, item, error))
                        return FALSE;
                gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
diff --git a/src/plugins/gs-plugin-flatpak-system.c b/src/plugins/gs-plugin-flatpak-system.c
index 383fa3e..4e27561 100644
--- a/src/plugins/gs-plugin-flatpak-system.c
+++ b/src/plugins/gs-plugin-flatpak-system.c
@@ -65,7 +65,7 @@ void
 gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
 {
        const gchar *id = gs_app_get_unique_id (app);
-       if (id != NULL && g_str_has_prefix (id, GS_FLATPAK_SYSTEM_PREFIX ":")) {
+       if (id != NULL && g_str_has_prefix (id, "system/flatpak/")) {
                gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
        }
 }
diff --git a/src/plugins/gs-plugin-flatpak-user.c b/src/plugins/gs-plugin-flatpak-user.c
index 218ecaf..5b63cd1 100644
--- a/src/plugins/gs-plugin-flatpak-user.c
+++ b/src/plugins/gs-plugin-flatpak-user.c
@@ -65,7 +65,7 @@ void
 gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
 {
        const gchar *id = gs_app_get_unique_id (app);
-       if (id != NULL && g_str_has_prefix (id, GS_FLATPAK_USER_PREFIX ":")) {
+       if (id != NULL && g_str_has_prefix (id, "user/flatpak/")) {
                gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
        }
 }


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