[gnome-software] Create AppStream runtimes with more accurate data



commit 7e4f449adaf91f87379b0f24ed00eac3cc36c2fc
Author: Richard Hughes <richard hughsie com>
Date:   Fri Feb 19 14:35:56 2016 +0000

    Create AppStream runtimes with more accurate data
    
    Using all the information from the donor application means we can use the
    correct ID prefix and show the correct refined metadata in the UI.
    
    It also means we can manage system-wide and per-user runtimes using xdg-app.

 src/plugins/gs-plugin-appstream.c |   51 +++++++++++++++++++++++++++++++-----
 1 files changed, 44 insertions(+), 7 deletions(-)
---
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index ce8be19..c29f1e0 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -467,6 +467,43 @@ gs_plugin_appstream_copy_metadata (GsApp *app, AsApp *item)
 }
 
 /**
+ * gs_plugin_appstream_create_runtime:
+ */
+static GsApp *
+gs_plugin_appstream_create_runtime (GsApp *parent, const gchar *runtime)
+{
+       g_autofree gchar *id = NULL;
+       g_autofree gchar *source = NULL;
+       g_auto(GStrv) id_split = NULL;
+       g_auto(GStrv) runtime_split = NULL;
+       g_autoptr(GsApp) app = NULL;
+
+       /* get the name/arch/branch */
+       runtime_split = g_strsplit (runtime, "/", -1);
+       if (g_strv_length (runtime_split) != 3)
+               return NULL;
+
+       /* find the parent app ID prefix */
+       id_split = g_strsplit (gs_app_get_id (parent), ":", 2);
+       if (g_strv_length (id_split) == 2) {
+               id = g_strdup_printf ("%s:%s.runtime",
+                                     id_split[0],
+                                     runtime_split[0]);
+       } else {
+               id = g_strdup_printf ("%s.runtime", runtime_split[0]);
+       }
+
+       /* create the complete GsApp from the single string */
+       app = gs_app_new (id);
+       source = g_strdup_printf ("runtime/%s", runtime);
+       gs_app_add_source (app, source);
+       gs_app_set_id_kind (app, AS_ID_KIND_RUNTIME);
+       gs_app_set_version (app, id_split[2]);
+
+       return g_steal_pointer (&app);
+}
+
+/**
  * gs_plugin_refine_item_management_plugin:
  */
 static void
@@ -489,13 +526,13 @@ gs_plugin_refine_item_management_plugin (GsApp *app, AsApp *item)
                        /* automatically add runtime */
                        runtime = as_bundle_get_runtime (bundle);
                        if (runtime != NULL) {
-                               g_autofree gchar *source = NULL;
-                               g_autoptr(GsApp) app_runtime = NULL;
-                               app_runtime = gs_app_new (runtime);
-                               source = g_strdup_printf ("runtime/%s", runtime);
-                               gs_app_add_source (app_runtime, source);
-                               gs_app_set_id_kind (app_runtime, AS_ID_KIND_RUNTIME);
-                               gs_app_set_runtime (app, app_runtime);
+                               g_autoptr(GsApp) app2 = NULL;
+                               app2 = gs_plugin_appstream_create_runtime (app, runtime);
+                               if (app2 != NULL) {
+                                       g_debug ("runtime for %s is %s",
+                                                gs_app_get_id (app), runtime);
+                                       gs_app_set_runtime (app, app2);
+                               }
                        }
 #endif
                        break;


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