[gnome-software/wip/hughsie/unique_id: 5/5] flatpak: Port to unique_id
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/unique_id: 5/5] flatpak: Port to unique_id
- Date: Thu, 28 Jul 2016 16:42:51 +0000 (UTC)
commit aabc251db37bcbfdd3826a61ef193c28cf7abb31
Author: Richard Hughes <richard hughsie com>
Date: Thu Jul 28 17:18:58 2016 +0100
flatpak: Port to unique_id
src/plugins/gs-flatpak.c | 53 +++++++++++++++++++++++++++++----------------
1 files changed, 34 insertions(+), 19 deletions(-)
---
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 94e4824..88b67b3 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -283,23 +283,29 @@ gs_flatpak_set_metadata_installed (GsFlatpak *self, GsApp *app,
}
static gchar *
-gs_flatpak_build_id (FlatpakInstallation *installation, FlatpakRef *xref)
+gs_flatpak_build_id (FlatpakRef *xref)
+{
+ if (flatpak_ref_get_kind (xref) == FLATPAK_REF_KIND_APP) {
+ return g_strdup_printf ("%s.desktop",
+ flatpak_ref_get_name (xref));
+ }
+ return g_strdup_printf ("%s.runtime",
+ flatpak_ref_get_name (xref));
+}
+
+static gchar *
+gs_flatpak_build_unique_id (FlatpakInstallation *installation, FlatpakRef *xref)
{
const gchar *prefix = GS_FLATPAK_SYSTEM_PREFIX;
+ 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;
/* flatpak doesn't use a suffix; AppStream does */
- if (flatpak_ref_get_kind (xref) == FLATPAK_REF_KIND_APP) {
- return g_strdup_printf ("%s:%s.desktop",
- prefix,
- flatpak_ref_get_name (xref));
- }
- return g_strdup_printf ("%s:%s.runtime",
- prefix,
- flatpak_ref_get_name (xref));
+ id = gs_flatpak_build_id (xref);
+ return g_strdup_printf ("%s:%s", prefix, id);
}
static GsApp *
@@ -307,7 +313,7 @@ gs_flatpak_create_installed (GsFlatpak *self,
FlatpakInstalledRef *xref,
GError **error)
{
- g_autofree gchar *id = NULL;
+ g_autofree gchar *unique_id = NULL;
g_autoptr(AsIcon) icon = NULL;
g_autoptr(GsApp) app = NULL;
@@ -332,11 +338,14 @@ gs_flatpak_create_installed (GsFlatpak *self,
}
/* create new object */
- id = gs_flatpak_build_id (self->installation, FLATPAK_REF (xref));
- app = gs_plugin_cache_lookup (self->plugin, id);
+ unique_id = gs_flatpak_build_unique_id (self->installation,
+ FLATPAK_REF (xref));
+ app = gs_plugin_cache_lookup (self->plugin, unique_id);
if (app == NULL) {
+ g_autofree gchar *id = gs_flatpak_build_id (FLATPAK_REF (xref));
app = gs_app_new (id);
- gs_plugin_cache_add (self->plugin, id, app);
+ gs_app_set_unique_id (app, unique_id);
+ gs_plugin_cache_add (self->plugin, unique_id, app);
}
gs_flatpak_set_metadata_installed (self, app, xref);
@@ -931,8 +940,8 @@ gs_flatpak_app_matches_xref (GsFlatpak *self, GsApp *app, FlatpakRef *xref)
g_autofree gchar *id = NULL;
/* check ID */
- id = gs_flatpak_build_id (self->installation, xref);
- if (g_strcmp0 (id, gs_app_get_id (app)) == 0)
+ id = gs_flatpak_build_unique_id (self->installation, xref);
+ if (g_strcmp0 (id, gs_app_get_unique_id (app)) == 0)
return TRUE;
/* do all the metadata items match? */
@@ -1576,7 +1585,7 @@ gs_flatpak_file_to_app_bundle (GsFlatpak *self,
{
gint size;
g_autofree gchar *content_type = NULL;
- g_autofree gchar *id_prefixed = NULL;
+ g_autofree gchar *unique_id = NULL;
g_autoptr(GBytes) appstream_gz = NULL;
g_autoptr(GBytes) icon_data = NULL;
g_autoptr(GBytes) metadata = NULL;
@@ -1591,11 +1600,17 @@ gs_flatpak_file_to_app_bundle (GsFlatpak *self,
}
/* create a virtual ID */
- id_prefixed = gs_flatpak_build_id (self->installation,
- FLATPAK_REF (xref_bundle));
+ unique_id = gs_flatpak_build_unique_id (self->installation,
+ FLATPAK_REF (xref_bundle));
+ app = gs_plugin_cache_lookup (self->plugin, unique_id);
+ if (app == NULL) {
+ g_autofree gchar *id = gs_flatpak_build_id (FLATPAK_REF (xref_bundle));
+ app = gs_app_new (id);
+ gs_app_set_unique_id (app, unique_id);
+ gs_plugin_cache_add (self->plugin, unique_id, app);
+ }
/* load metadata */
- app = gs_app_new (id_prefixed);
gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
gs_app_set_state (app, AS_APP_STATE_AVAILABLE_LOCAL);
gs_app_set_size_installed (app, flatpak_bundle_ref_get_installed_size (xref_bundle));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]