[gnome-software/wip/kalev/gnome-3-22: 62/96] trivial: Add the concept of a GsFlatpak identifier
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/kalev/gnome-3-22: 62/96] trivial: Add the concept of a GsFlatpak identifier
- Date: Tue, 7 Mar 2017 16:29:17 +0000 (UTC)
commit a04cf0b4003afc9573bec58962def84e3f77e004
Author: Richard Hughes <richard hughsie com>
Date: Tue Feb 21 15:59:09 2017 +0000
trivial: Add the concept of a GsFlatpak identifier
This allows us to match the application using more than just the scope.
src/plugins/gs-flatpak.c | 15 +++++++++++++++
src/plugins/gs-flatpak.h | 3 +++
src/plugins/gs-plugin-flatpak.c | 26 ++++++++++++++++++++------
3 files changed, 38 insertions(+), 6 deletions(-)
---
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 23de4ed..2293b8a 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -43,6 +43,7 @@ struct _GsFlatpak {
AsAppScope scope;
GsPlugin *plugin;
AsStore *store;
+ gchar *id;
guint changed_id;
};
@@ -75,6 +76,7 @@ gs_flatpak_create_app (GsFlatpak *self, FlatpakRef *xref)
app = gs_app_new (id);
gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_FLATPAK);
gs_app_set_branch (app, flatpak_ref_get_branch (xref));
+ gs_app_set_flatpak_object_id (app, gs_flatpak_get_id (self));
if (flatpak_installation_get_is_user (self->installation)) {
gs_app_set_scope (app, AS_APP_SCOPE_USER);
} else {
@@ -2793,6 +2795,18 @@ gs_flatpak_store_app_removed_cb (AsStore *store, AsApp *app, GsFlatpak *self)
gs_plugin_cache_remove (self->plugin, as_app_get_unique_id (app));
}
+const gchar *
+gs_flatpak_get_id (GsFlatpak *self)
+{
+ if (self->id == NULL) {
+ GString *str = g_string_new ("GsFlatpak");
+ g_string_append_printf (str, "-%s",
+ as_app_scope_to_string (self->scope));
+ self->id = g_string_free (str, FALSE);
+ }
+ return self->id;
+}
+
AsAppScope
gs_flatpak_get_scope (GsFlatpak *self)
{
@@ -2811,6 +2825,7 @@ gs_flatpak_finalize (GObject *object)
self->changed_id = 0;
}
+ g_free (self->id);
g_object_unref (self->plugin);
g_object_unref (self->store);
g_hash_table_unref (self->broken_remotes);
diff --git a/src/plugins/gs-flatpak.h b/src/plugins/gs-flatpak.h
index 5eb13ed..0b72a7a 100644
--- a/src/plugins/gs-flatpak.h
+++ b/src/plugins/gs-flatpak.h
@@ -38,15 +38,18 @@ G_DECLARE_FINAL_TYPE (GsFlatpak, gs_flatpak, GS, FLATPAK, GObject)
#define gs_app_get_flatpak_branch(app) gs_app_get_metadata_item(app,"flatpak::branch")
#define gs_app_get_flatpak_commit(app) gs_app_get_metadata_item(app,"flatpak::commit")
#define gs_app_get_flatpak_file_type(app) gs_app_get_metadata_item(app,"flatpak::file-type")
+#define gs_app_get_flatpak_object_id(app) gs_app_get_metadata_item(app,"flatpak::object-id")
#define gs_app_set_flatpak_name(app,val) gs_app_set_metadata(app,"flatpak::name",val)
#define gs_app_set_flatpak_arch(app,val) gs_app_set_metadata(app,"flatpak::arch",val)
#define gs_app_set_flatpak_branch(app,val) gs_app_set_metadata(app,"flatpak::branch",val)
#define gs_app_set_flatpak_commit(app,val) gs_app_set_metadata(app,"flatpak::commit",val)
#define gs_app_set_flatpak_file_type(app,val) gs_app_set_metadata(app,"flatpak::file-type",val)
+#define gs_app_set_flatpak_object_id(app,val) gs_app_set_metadata(app,"flatpak::object-id",val)
GsFlatpak *gs_flatpak_new (GsPlugin *plugin,
FlatpakInstallation *installation);
AsAppScope gs_flatpak_get_scope (GsFlatpak *self);
+const gchar *gs_flatpak_get_id (GsFlatpak *self);
gboolean gs_flatpak_setup (GsFlatpak *self,
GCancellable *cancellable,
GError **error);
diff --git a/src/plugins/gs-plugin-flatpak.c b/src/plugins/gs-plugin-flatpak.c
index 1c87277..6dc7f3b 100644
--- a/src/plugins/gs-plugin-flatpak.c
+++ b/src/plugins/gs-plugin-flatpak.c
@@ -117,6 +117,7 @@ gs_plugin_flatpak_add_installation (GsPlugin *plugin,
flatpak = gs_flatpak_new (plugin, installation);
if (!gs_flatpak_setup (flatpak, cancellable, error))
return FALSE;
+ g_debug ("successfully set up %s", gs_flatpak_get_id (flatpak));
/* add objects that set up correctly */
g_ptr_array_add (priv->flatpaks, g_steal_pointer (&flatpak));
@@ -247,6 +248,7 @@ static GsFlatpak *
gs_plugin_flatpak_get_handler (GsPlugin *plugin, GsApp *app)
{
GsPluginData *priv = gs_plugin_get_data (plugin);
+ const gchar *object_id;
/* only process this app if was created by this plugin */
if (g_strcmp0 (gs_app_get_management_plugin (app),
@@ -254,15 +256,27 @@ gs_plugin_flatpak_get_handler (GsPlugin *plugin, GsApp *app)
return NULL;
}
+ /* specified an explicit name */
+ object_id = gs_app_get_flatpak_object_id (app);
+ if (object_id != NULL) {
+ for (guint i = 0; i < priv->flatpaks->len; i++) {
+ GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+ if (g_strcmp0 (gs_flatpak_get_id (flatpak), object_id) == 0) {
+ g_debug ("chose %s using ID",
+ gs_flatpak_get_id (flatpak));
+ return flatpak;
+ }
+ }
+ }
+
+ /* find a scope that matches */
for (guint i = 0; i < priv->flatpaks->len; i++) {
GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
-
- /* check scope */
- if (!_as_app_scope_is_compatible (gs_flatpak_get_scope (flatpak),
- gs_app_get_scope (app))) {
- continue;
+ if (_as_app_scope_is_compatible (gs_flatpak_get_scope (flatpak),
+ gs_app_get_scope (app))) {
+ g_debug ("chose %s using scope", gs_flatpak_get_id (flatpak));
+ return flatpak;
}
- return flatpak;
}
return NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]