[gnome-builder] flatpak: Use manifest checksum in runtime id



commit cf33af14e7d09f6d534ea56c388e4fd26fafc25f
Author: Matthew Leeds <mleeds redhat com>
Date:   Thu Nov 17 00:15:59 2016 -0600

    flatpak: Use manifest checksum in runtime id
    
    By including a checksum of the contents of the flatpak manifest in its
    runtime id, we can ensure that changing the manifset results in using a
    different build directory (which allows the changes to take effect).
    However this approach has a few disadvantages:
    (1) If the manifest never returns to a previous state, that build
    directory's disk space is wasted.
    (2) The runtime id appears in the omni bar which is ugly.
    (3) The runtime id is written to the .buildconfig file which means if
    the project is reloaded with an edited manifest, the runtime appears
    as missing.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774509

 plugins/flatpak/gbp-flatpak-runtime-provider.c |   25 +++++++++++++++++++++--
 1 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-runtime-provider.c b/plugins/flatpak/gbp-flatpak-runtime-provider.c
index 1cb9193..03c9c0c 100644
--- a/plugins/flatpak/gbp-flatpak-runtime-provider.c
+++ b/plugins/flatpak/gbp-flatpak-runtime-provider.c
@@ -391,9 +391,28 @@ gbp_flatpak_runtime_provider_load_manifests (GbpFlatpakRuntimeProvider  *self,
   for (guint i = 0; i < ar->len; i++)
     {
       FlatpakManifest *manifest = g_ptr_array_index (ar, i);
-      gchar *id;
+      gchar *filename;
+      g_autofree gchar *hash = NULL;
+      g_autofree gchar *id = NULL;
+      g_autofree gchar *manifest_data = NULL;
+      GChecksum *checksum;
+
+      if (g_file_get_contents (g_file_get_path (manifest->file),
+                               &manifest_data,
+                               NULL, NULL))
+        {
+          checksum = g_checksum_new (G_CHECKSUM_SHA1);
+          g_checksum_update (checksum, (guchar *)manifest_data, -1);
+          hash = g_strdup (g_checksum_get_string (checksum));
+          g_checksum_free (checksum);
+        }
+
+      filename = g_file_get_basename (manifest->file);
+      if (hash != NULL)
+        id = g_strdup_printf ("%s@%s", filename, hash);
+      else
+        id = g_strdup (filename);
 
-      id = g_file_get_basename (manifest->file);
       if (contains_id (runtimes, id))
         continue;
 
@@ -407,7 +426,7 @@ gbp_flatpak_runtime_provider_load_manifests (GbpFlatpakRuntimeProvider  *self,
                                      "app-id", manifest->app_id,
                                      "context", context,
                                      "id", id,
-                                     "display-name", id,
+                                     "display-name", filename,
                                      NULL));
     }
 


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