deltas: Support including detached metadata in static deltas
authorAlexander Larsson <alexl@redhat.com>
Mon, 19 Oct 2015 08:10:50 +0000 (10:10 +0200)
committerAlexander Larsson <alexl@redhat.com>
Tue, 10 Nov 2015 07:56:16 +0000 (08:56 +0100)
This is very useful for the inline-parts case, as you can then include
detached signatures in a single file representing the commit.

It is not as important for the generic pull case, as the detached
metadata is only a single small file. Additionally the detached
metadata is not content referenced and may change after the static
delta file was created, so we need to pull the latest version anyway.

src/libostree/ostree-repo-pull.c
src/libostree/ostree-repo-static-delta-compilation.c
src/libostree/ostree-repo-static-delta-core.c

index 4c3b14bf75b55d36925b519edc3b6fd524bb3738..76cd0273d463b23a173f2e72d92cfb9bc1e57a8c 100644 (file)
@@ -1532,7 +1532,19 @@ process_one_static_delta (OtPullData   *pull_data,
     
     if (!have_to_commit)
       {
-        FetchObjectData *fetch_data = g_new0 (FetchObjectData, 1);
+        FetchObjectData *fetch_data;
+        g_autofree char *detached_path = _ostree_get_relative_static_delta_path (from_revision, to_revision, "commitmeta");
+        g_autoptr(GVariant) detached_data = NULL;
+
+        detached_data = g_variant_lookup_value (metadata, detached_path, G_VARIANT_TYPE("a{sv}"));
+        if (detached_data && !ostree_repo_write_commit_detached_metadata (pull_data->repo,
+                                                                          to_revision,
+                                                                          detached_data,
+                                                                          cancellable,
+                                                                          error))
+          goto out;
+
+        fetch_data = g_new0 (FetchObjectData, 1);
         fetch_data->pull_data = pull_data;
         fetch_data->object = ostree_object_name_serialize (to_checksum, OSTREE_OBJECT_TYPE_COMMIT);
         fetch_data->is_detached_meta = FALSE;
index d051d01ce4764533a6d02bb16f935e3d83a338f6..530b3a75fd25aa88034529003b63e295dfcde006 100644 (file)
@@ -1260,9 +1260,9 @@ ostree_repo_static_delta_generate (OstreeRepo                   *self,
   g_autoptr(GFile) descriptor_dir = NULL;
   g_autoptr(GVariant) tmp_metadata = NULL;
   g_autoptr(GVariant) fallback_headers = NULL;
+  g_autoptr(GVariant) detached = NULL;
   gboolean inline_parts;
   g_autoptr(GFile) tmp_dir = NULL;
-
   builder.parts = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_static_delta_part_builder_unref);
   builder.fallback_objects = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref);
 
@@ -1465,6 +1465,15 @@ ostree_repo_static_delta_generate (OstreeRepo                   *self,
                              cancellable, error))
     goto out;
 
+  if (!ostree_repo_read_commit_detached_metadata (self, to, &detached, cancellable, error))
+    goto out;
+
+  if (detached)
+    {
+      g_autofree char *detached_key = _ostree_get_relative_static_delta_path (from, to, "commitmeta");
+      g_variant_builder_add (&metadata_builder, "{sv}", detached_key, detached);
+    }
+
   /* Generate OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT */
   {
     GDateTime *now = g_date_time_new_now_utc ();
index 2e445789e8e5edf39a0f9dad8de177ee1be0a476..e3490fd698d1b95ddd180363cf69479fc896cfed 100644 (file)
@@ -254,6 +254,8 @@ ostree_repo_static_delta_execute_offline (OstreeRepo                    *self,
 
   /* Parsing OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT */
 
+  metadata = g_variant_get_child_value (meta, 0);
+
   /* Write the to-commit object */
   {
     g_autoptr(GVariant) to_csum_v = NULL;
@@ -292,6 +294,17 @@ ostree_repo_static_delta_execute_offline (OstreeRepo                    *self,
     
     if (!have_to_commit)
       {
+        g_autofree char *detached_path = _ostree_get_relative_static_delta_path (from_checksum, to_checksum, "commitmeta");
+        g_autoptr(GVariant) detached_data = NULL;
+
+        detached_data = g_variant_lookup_value (metadata, detached_path, G_VARIANT_TYPE("a{sv}"));
+        if (detached_data && !ostree_repo_write_commit_detached_metadata (self,
+                                                                          to_checksum,
+                                                                          detached_data,
+                                                                          cancellable,
+                                                                          error))
+          goto out;
+
         to_commit = g_variant_get_child_value (meta, 4);
         if (!ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_COMMIT,
                                          to_checksum, to_commit, NULL,
@@ -309,7 +322,6 @@ ostree_repo_static_delta_execute_offline (OstreeRepo                    *self,
     }
 
   headers = g_variant_get_child_value (meta, 6);
-  metadata = g_variant_get_child_value (meta, 0);
   n = g_variant_n_children (headers);
   for (i = 0; i < n; i++)
     {