[ostree/wip/delta2: 19/21] delta: Write out object length before write calls



commit b50c286ba970b8bec55227ad22df9dd4323b7110
Author: Colin Walters <walters verbum org>
Date:   Mon Apr 28 08:51:54 2014 -0400

    delta: Write out object length before write calls
    
    This will allow us to stream objects to disk rather than doing write
    tmpfile + open + read + write.

 .../ostree-repo-static-delta-compilation.c         |    5 ++
 .../ostree-repo-static-delta-processing.c          |   51 +++++++++++++-------
 2 files changed, 38 insertions(+), 18 deletions(-)
---
diff --git a/src/libostree/ostree-repo-static-delta-compilation.c 
b/src/libostree/ostree-repo-static-delta-compilation.c
index 7f98e64..9c9d603 100644
--- a/src/libostree/ostree-repo-static-delta-compilation.c
+++ b/src/libostree/ostree-repo-static-delta-compilation.c
@@ -160,6 +160,11 @@ process_one_object (OstreeRepo                       *repo,
       current_part->payload->len += bytes_read;
     }
       
+  /* A little lame here to duplicate the content size - but if in the
+   * future we do rsync-style rolling checksums, then we'll have
+   * multiple write calls.
+   */
+  _ostree_write_varuint64 (current_part->operations, content_size);
   g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_WRITE);
   _ostree_write_varuint64 (current_part->operations, object_payload_start);
   _ostree_write_varuint64 (current_part->operations, content_size);
diff --git a/src/libostree/ostree-repo-static-delta-processing.c 
b/src/libostree/ostree-repo-static-delta-processing.c
index 271c39f..afbaa3b 100644
--- a/src/libostree/ostree-repo-static-delta-processing.c
+++ b/src/libostree/ostree-repo-static-delta-processing.c
@@ -38,6 +38,9 @@ typedef struct {
 
   const guint8   *opdata;
   guint           oplen;
+  
+  gboolean        object_start;
+  guint64         object_size;
 
   OstreeObjectType output_objtype;
   const guint8   *output_target;
@@ -144,6 +147,23 @@ _ostree_static_delta_part_validate (OstreeRepo     *repo,
   return ret;
 }
 
+static gboolean
+read_varuint64 (StaticDeltaExecutionState  *state,
+                guint64                    *out_value,
+                GError                    **error)
+{
+  gsize bytes_read;
+  if (!_ostree_read_varuint64 (state->opdata, state->oplen, out_value, &bytes_read))
+    {
+      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                           "Unexpected EOF reading varint");
+      return FALSE;
+    }
+  state->opdata += bytes_read;
+  state->oplen -= bytes_read;
+  return TRUE;
+}
+
 gboolean
 _ostree_static_delta_part_execute_raw (OstreeRepo      *repo,
                                        GVariant        *objects,
@@ -178,11 +198,21 @@ _ostree_static_delta_part_execute_raw (OstreeRepo      *repo,
 
   state->oplen = g_variant_n_children (ops);
   state->opdata = g_variant_get_data (ops);
+  state->object_start = TRUE;
   while (state->oplen > 0)
     {
-      guint8 opcode = state->opdata[0];
+      guint8 opcode;
       OstreeStaticDeltaOperation *op;
 
+      if (state->object_start)
+        {
+          if (!read_varuint64 (state, &state->object_size, error))
+            goto out;
+          state->object_start = FALSE;
+        }
+
+      opcode = state->opdata[0];
+
       if (G_UNLIKELY (opcode == 0 || opcode >= G_N_ELEMENTS (op_dispatch_table)))
         {
           g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
@@ -376,23 +406,6 @@ _ostree_static_delta_part_execute_finish (OstreeRepo      *repo,
 }
 
 static gboolean
-read_varuint64 (StaticDeltaExecutionState  *state,
-                guint64                    *out_value,
-                GError                    **error)
-{
-  gsize bytes_read;
-  if (!_ostree_read_varuint64 (state->opdata, state->oplen, out_value, &bytes_read))
-    {
-      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                           "Unexpected EOF reading varint");
-      return FALSE;
-    }
-  state->opdata += bytes_read;
-  state->oplen -= bytes_read;
-  return TRUE;
-}
-
-static gboolean
 validate_ofs (StaticDeltaExecutionState  *state,
               guint64                     offset,
               guint64                     length,
@@ -559,6 +572,8 @@ dispatch_close (OstreeRepo                 *repo,
   state->output_target = NULL;
   g_clear_object (&state->output_tmp_path);
 
+  state->object_start = TRUE;
+
   state->checksum_index++;
   if (state->checksum_index < state->n_checksums)
     {


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