[gnome-software/wip/kalev/gnome-3-22: 45/96] Fix launching apps after updating
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/kalev/gnome-3-22: 45/96] Fix launching apps after updating
- Date: Tue, 7 Mar 2017 16:27:37 +0000 (UTC)
commit ec4eb1e85c51d65421bdfa6cdc5fe51a114feaff
Author: Joaquim Rocha <jrocha endlessm com>
Date: Fri Jan 13 17:24:50 2017 +0100
Fix launching apps after updating
When an app has an update and the new updated app needs a different
runtime, unless the AppStream of the repo has been very recently
updated, the app not realize that it needs to eventually install a
new runtime.
These changes get the runtime information from the remote ref (meaning
the real runtime for the app) before deciding whether the runtime
needs to be installed which prevents the problem above.
src/plugins/gs-flatpak.c | 101 ++++++++++++++++++++++++++++++++++-----------
1 files changed, 76 insertions(+), 25 deletions(-)
---
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 119c9d7..8f34d7b 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -1457,6 +1457,27 @@ gs_plugin_refine_item_state (GsFlatpak *self,
return TRUE;
}
+static GsApp *
+gs_flatpak_create_runtime_from_metadata (GsFlatpak *self,
+ const GsApp *app,
+ const gchar *data,
+ const gsize length,
+ GError **error)
+{
+ g_autofree gchar *runtime = NULL;
+ g_autoptr(GKeyFile) kf = NULL;
+
+ kf = g_key_file_new ();
+ if (!g_key_file_load_from_data (kf, data, length, G_KEY_FILE_NONE, error)) {
+ return NULL;
+ }
+ runtime = g_key_file_get_string (kf, "Application", "runtime", error);
+ if (runtime == NULL) {
+ return NULL;
+ }
+ return gs_appstream_create_runtime (self->plugin, app, runtime);
+}
+
static gboolean
gs_flatpak_set_app_metadata (GsFlatpak *self,
GsApp *app,
@@ -1526,6 +1547,40 @@ gs_flatpak_set_app_metadata (GsFlatpak *self,
return TRUE;
}
+static GBytes *
+gs_flatpak_fetch_remote_metadata (GsFlatpak *self,
+ GsApp *app,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GBytes) data = NULL;
+ g_autoptr(FlatpakRef) xref = NULL;
+
+ /* no origin */
+ if (gs_app_get_origin (app) == NULL) {
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_NOT_SUPPORTED,
+ "no origin set for %s",
+ gs_app_get_unique_id (app));
+ return NULL;
+ }
+
+ /* fetch from the server */
+ xref = gs_flatpak_create_fake_ref (app, error);
+ if (xref == NULL)
+ return NULL;
+ data = flatpak_installation_fetch_remote_metadata_sync (self->installation,
+ gs_app_get_origin (app),
+ xref,
+ cancellable,
+ error);
+ if (data == NULL) {
+ return NULL;
+ }
+ return g_steal_pointer (&data);
+}
+
static gboolean
gs_plugin_refine_item_metadata (GsFlatpak *self,
GsApp *app,
@@ -1573,30 +1628,8 @@ gs_plugin_refine_item_metadata (GsFlatpak *self,
return FALSE;
str = contents;
} else {
- g_autoptr(FlatpakRef) xref = NULL;
-
- /* no origin */
- if (gs_app_get_origin (app) == NULL) {
- g_set_error (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_NOT_SUPPORTED,
- "no origin set for %s",
- gs_app_get_unique_id (app));
- return FALSE;
- }
-
- /* fetch from the server */
- xref = gs_flatpak_create_fake_ref (app, error);
- if (xref == NULL)
- return FALSE;
- data = flatpak_installation_fetch_remote_metadata_sync (self->installation,
- gs_app_get_origin (app),
- xref,
- cancellable,
- error);
- if (data == NULL) {
- return FALSE;
- }
+ data = gs_flatpak_fetch_remote_metadata (self, app, cancellable,
+ error);
str = g_bytes_get_data (data, &len);
}
@@ -2008,12 +2041,28 @@ install_runtime_for_app (GsFlatpak *self,
GCancellable *cancellable,
GError **error)
{
- GsApp *runtime = gs_app_get_update_runtime (app);
+ GsApp *runtime;
+ gsize len;
+ const gchar *str;
+ g_autoptr(GBytes) data = gs_flatpak_fetch_remote_metadata (self, app,
+ cancellable,
+ error);
+
+ if (data == NULL) {
+ gs_app_set_state_recover (app);
+ return FALSE;
+ }
+
+ str = g_bytes_get_data (data, &len);
+ runtime = gs_flatpak_create_runtime_from_metadata (self, app, str, len,
+ error);
/* no runtime required */
if (runtime == NULL)
return TRUE;
+ gs_app_set_update_runtime (app, runtime);
+
/* the runtime could come from a different remote to the app */
if (!gs_refine_item_metadata (self, runtime, cancellable, error)) {
gs_app_set_state_recover (app);
@@ -2065,6 +2114,8 @@ install_runtime_for_app (GsFlatpak *self,
gs_app_get_id (runtime));
}
+ gs_app_set_runtime (app, runtime);
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]