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



commit 0929b3b8f3e3d017935b37bb791f7fbe8915eda2
Author: Richard Hughes <richard hughsie com>
Date:   Mon Aug 1 10:08:13 2016 +0100

    f

 src/plugins/gs-flatpak.c                 |   25 +++++++++++++------------
 src/plugins/gs-plugin-appstream.c        |   19 +++++++++----------
 src/plugins/gs-plugin-limba.c            |   12 ++++++++----
 src/plugins/gs-plugin-shell-extensions.c |    9 ++++++++-
 src/plugins/gs-plugin-snap.c             |   14 ++++++++------
 5 files changed, 46 insertions(+), 33 deletions(-)
---
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index f155964..f7fbb24 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -302,23 +302,24 @@ gs_flatpak_build_id (FlatpakRef *xref)
 static gchar *
 gs_flatpak_build_unique_id (FlatpakInstallation *installation, FlatpakRef *xref)
 {
-       const gchar *scope = "system";
+       AsAppKind kind = AS_APP_KIND_DESKTOP;
+       AsAppScope scope = AS_APP_SCOPE_SYSTEM;
        g_autofree gchar *id = NULL;
-       g_autoptr(AsAppRef) app_ref = NULL;
 
        /* use a different prefix if we're somehow running this as per-user */
        if (flatpak_installation_get_is_user (installation))
-               scope = "user";
-
-       /* flatpak doesn't use a suffix; AppStream does */
+               scope = AS_APP_SCOPE_USER;
+       if (flatpak_ref_get_kind (xref) == FLATPAK_REF_KIND_RUNTIME)
+               kind = AS_APP_KIND_RUNTIME;
        id = gs_flatpak_build_id (xref);
-       app_ref = as_app_ref_new (id);
-       as_app_ref_set_scope (app_ref, scope);
-       as_app_ref_set_system (app_ref, "flatpak");
-       as_app_ref_set_kind (app_ref, _flatpak_ref_kind_to_string (flatpak_ref_get_kind (xref)));
-       as_app_ref_set_arch (app_ref, flatpak_ref_get_arch (xref));
-       as_app_ref_set_branch (app_ref, flatpak_ref_get_branch (xref));
-       return as_app_ref_to_string (app_ref);
+       return as_utils_unique_id_build (scope,
+                                        AS_BUNDLE_KIND_FLATPAK,
+                                        NULL,  /* origin */
+                                        kind,
+                                        id,
+                                        flatpak_ref_get_arch (xref),
+                                        flatpak_ref_get_branch (xref),
+                                        NULL); /* version */
 }
 
 static GsApp *
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index db69f7e..09dac5e 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -276,19 +276,17 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 
        /* add keyword for non-package sources */
        for (i = 0; i < items->len; i++) {
-               const gchar *system;
-               g_autoptr(AsAppRef) app_ref = NULL;
+               g_auto(GStrv) split = NULL;
                app = g_ptr_array_index (items, i);
-               app_ref = as_app_ref_new_from_string (as_app_get_unique_id (app));
-               if (app_ref == NULL)
+               split = g_strsplit (as_app_get_unique_id (app), "/", -1);
+               if (g_strv_length (split) != 8)
                        continue;
-               system = as_app_ref_get_system (app_ref);
-               if (g_strcmp0 (system, "package") == 0)
+               if (g_strcmp0 (split[1], "package") == 0)
                        continue;
-               if (g_strcmp0 (system, "*") == 0)
+               if (g_strcmp0 (split[1], "*") == 0)
                        continue;
-               g_debug ("Adding keyword '%s' to %s", system, as_app_get_id (app));
-               as_app_add_keyword (app, NULL, system);
+               g_debug ("Adding keyword '%s' to %s", split[1], as_app_get_id (app));
+               as_app_add_keyword (app, NULL, split[1]);
        }
 
        /* fix up these */
@@ -335,7 +333,8 @@ gs_plugin_refine_from_id (GsPlugin *plugin,
 
        /* nothing found */
        g_debug ("searching appstream for %s", unique_id);
-       item = as_store_get_app_by_unique_id (priv->store, unique_id);
+       item = as_store_get_app_by_unique_id (priv->store, unique_id,
+                                             AS_STORE_SEARCH_FLAG_NONE);
        if (item == NULL) {
                const gchar *id = gs_app_get_id (app);
                g_debug ("looking for fallback of %s", id);
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
index 94124ba..7d187b3 100644
--- a/src/plugins/gs-plugin-limba.c
+++ b/src/plugins/gs-plugin-limba.c
@@ -282,7 +282,6 @@ gs_plugin_app_from_pki (LiPkgInfo *pki)
 {
        const gchar *cptkind_str;
        GsApp *app;
-       g_autoptr(AsAppRef) app_ref = NULL;
        g_autofree gchar *unique_id = NULL;
 
        cptkind_str = li_pkg_info_get_component_kind (pki);
@@ -300,9 +299,14 @@ gs_plugin_app_from_pki (LiPkgInfo *pki)
        }
 
        /* create a unique ID for deduplication, TODO: scope?, branch?, arch? */
-       app_ref = as_app_ref_new (id);
-       as_app_ref_set_system (app_ref, "limba");
-       unique_id = as_app_ref_to_string (app_ref);
+       unique_id = as_utils_unique_id_build (AS_APP_SCOPE_UNKNOWN,
+                                             AS_BUNDLE_KIND_LIMBA,
+                                             NULL,     /* origin */
+                                             AS_APP_KIND_UNKNOWN,
+                                             id,
+                                             NULL,     /* arch */
+                                             NULL,     /* branch */
+                                             NULL);    /* version */
 
        gs_app_set_unique_id (app, unique_id);
        gs_app_set_management_plugin (app, "limba");
diff --git a/src/plugins/gs-plugin-shell-extensions.c b/src/plugins/gs-plugin-shell-extensions.c
index 9e2de2e..76a7206 100644
--- a/src/plugins/gs-plugin-shell-extensions.c
+++ b/src/plugins/gs-plugin-shell-extensions.c
@@ -124,7 +124,14 @@ gs_plugin_shell_extensions_add_app (GsPlugin *plugin,
        g_autoptr(AsIcon) ic = NULL;
 
        id = gs_plugin_shell_extensions_id_from_uuid (uuid);
-       unique_id = g_strdup_printf ("user/*/*/shell-extension/%s/*/*", id);
+       unique_id = as_utils_unique_id_build (AS_APP_SCOPE_USER,
+                                             AS_BUNDLE_KIND_UNKNOWN,
+                                             NULL,     /* origin */
+                                             AS_APP_KIND_SHELL_EXTENSION,
+                                             id,
+                                             NULL,     /* arch */
+                                             NULL,     /* branch */
+                                             NULL);    /* version */
        gs_app_set_id (app, id);
        gs_app_set_unique_id (app, unique_id);
        gs_app_set_metadata (app, "GnomeSoftware::Creator",
diff --git a/src/plugins/gs-plugin-snap.c b/src/plugins/gs-plugin-snap.c
index b171673..0745e97 100644
--- a/src/plugins/gs-plugin-snap.c
+++ b/src/plugins/gs-plugin-snap.c
@@ -327,7 +327,6 @@ get_apps (GsPlugin *plugin,
        for (l = snaps; l != NULL; l = l->next) {
                JsonObject *package = json_node_get_object (l->data);
                g_autoptr(GsApp) app = NULL;
-               g_autoptr(AsAppRef) app_ref = NULL;
                g_autofree gchar *unique_id = NULL;
                const gchar *id;
 
@@ -337,11 +336,14 @@ get_apps (GsPlugin *plugin,
                        continue;
 
                /* create a unique ID for deduplication, TODO: branch?, arch? */
-               app_ref = as_app_ref_new (id);
-               as_app_ref_set_scope (app_ref, "system");
-               as_app_ref_set_system (app_ref, "snap");
-               unique_id = as_app_ref_to_string (app_ref);
-
+               unique_id = as_utils_unique_id_build (AS_APP_SCOPE_SYSTEM,
+                                                     AS_BUNDLE_KIND_SNAP,
+                                                     NULL,     /* origin */
+                                                     AS_APP_KIND_UNKNOWN,
+                                                     id,
+                                                     NULL,     /* arch */
+                                                     NULL,     /* branch */
+                                                     NULL);    /* version */
                app = gs_app_new (id);
                gs_app_set_unique_id (app, unique_id);
                gs_app_set_management_plugin (app, "snap");


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