deltas: Break out _ostree_repo_static_delta_superblock_digest() helper
authorAlexander Larsson <alexl@redhat.com>
Mon, 31 Aug 2020 15:21:43 +0000 (17:21 +0200)
committerAlexander Larsson <alexl@redhat.com>
Fri, 11 Sep 2020 10:03:28 +0000 (12:03 +0200)
This loads and makes a digest for a delta superblock. The previous
code was used when generating the deltas section in the summary
file. This changes nothing, but is in preparation for using similar
formats in a separate delta index file.

src/libostree/ostree-repo-static-delta-core.c
src/libostree/ostree-repo-static-delta-private.h
src/libostree/ostree-repo.c

index d12bf4394302f647d76793ae0d8f91e4c37aaff8..835ec7f3e5dded062530cc3d3ccf891694bc22bd 100644 (file)
@@ -54,6 +54,28 @@ _ostree_static_delta_parse_checksum_array (GVariant      *array,
   return TRUE;
 }
 
+GVariant *
+_ostree_repo_static_delta_superblock_digest (OstreeRepo    *repo,
+                                             const char    *from,
+                                             const char    *to,
+                                             GCancellable  *cancellable,
+                                             GError       **error)
+{
+  g_autofree char *superblock = _ostree_get_relative_static_delta_superblock_path ((from && from[0]) ? from : NULL, to);
+  glnx_autofd int superblock_file_fd = -1;
+  guint8 digest[OSTREE_SHA256_DIGEST_LEN];
+
+  if (!glnx_openat_rdonly (repo->repo_dir_fd, superblock, TRUE, &superblock_file_fd, error))
+    return NULL;
+
+  g_autoptr(GBytes) superblock_content = ot_fd_readall_or_mmap (superblock_file_fd, 0, error);
+  if (!superblock_content)
+    return NULL;
+
+  ot_checksum_bytes (superblock_content, digest);
+
+  return ot_gvariant_new_bytearray (digest, sizeof (digest));
+}
 
 /**
  * ostree_repo_list_static_delta_names:
index 155acd5297349e1ac338f85829ca8251ec8e8d52..ff8de9d4fa37b0801d4f2d59ef2ba3f8d2c8befa 100644 (file)
@@ -190,6 +190,12 @@ _ostree_repo_static_delta_query_exists (OstreeRepo                 *repo,
                                         gboolean                   *out_exists,
                                         GCancellable               *cancellable,
                                         GError                    **error);
+GVariant *
+_ostree_repo_static_delta_superblock_digest (OstreeRepo    *repo,
+                                             const char    *from,
+                                             const char    *to,
+                                             GCancellable  *cancellable,
+                                             GError       **error);
 
 gboolean
 _ostree_repo_static_delta_dump (OstreeRepo                 *repo,
index 95eb0efcbbc905820d6e62b2eaead70455f13477..621668d7d661edb8e4837571d5570a2ba79feb13 100644 (file)
@@ -5793,25 +5793,18 @@ ostree_repo_regenerate_summary (OstreeRepo     *self,
       {
         g_autofree char *from = NULL;
         g_autofree char *to = NULL;
-        if (!_ostree_parse_delta_name (delta_names->pdata[i], &from, &to, error))
-          return FALSE;
+        GVariant *digest;
 
-        g_autofree char *superblock = _ostree_get_relative_static_delta_superblock_path ((from && from[0]) ? from : NULL, to);
-        glnx_autofd int superblock_file_fd = -1;
-
-        if (!glnx_openat_rdonly (self->repo_dir_fd, superblock, TRUE, &superblock_file_fd, error))
+        if (!_ostree_parse_delta_name (delta_names->pdata[i], &from, &to, error))
           return FALSE;
 
-        g_autoptr(GBytes) superblock_content = ot_fd_readall_or_mmap (superblock_file_fd, 0, error);
-        if (!superblock_content)
+        digest = _ostree_repo_static_delta_superblock_digest (self,
+                                                              (from && from[0]) ? from : NULL,
+                                                              to, cancellable, error);
+        if (digest == NULL)
           return FALSE;
-        g_auto(OtChecksum) hasher = { 0, };
-        ot_checksum_init (&hasher);
-        ot_checksum_update_bytes (&hasher, superblock_content);
-        guint8 digest[OSTREE_SHA256_DIGEST_LEN];
-        ot_checksum_get_digest (&hasher, digest, sizeof (digest));
 
-        g_variant_dict_insert_value (&deltas_builder, delta_names->pdata[i], ot_gvariant_new_bytearray (digest, sizeof (digest)));
+        g_variant_dict_insert_value (&deltas_builder, delta_names->pdata[i], digest);
       }
 
     if (delta_names->len > 0)