浏览代码

cache sync: move stat initialization to main unpack

Marian Beermann 8 年之前
父节点
当前提交
795cdfc9ab
共有 3 个文件被更改,包括 16 次插入5 次删除
  1. 1 4
      src/borg/cache_sync/cache_sync.c
  2. 14 1
      src/borg/cache_sync/unpack.h
  3. 1 0
      src/borg/cache_sync/unpack_template.h

+ 1 - 4
src/borg/cache_sync/cache_sync.c

@@ -19,11 +19,8 @@ cache_sync_init(HashIndex *chunks)
     }
 
     unpack_init(&ctx->ctx);
-
+    /* needs to be set only once */
     ctx->ctx.user.chunks = chunks;
-    ctx->ctx.user.last_error = NULL;
-    ctx->ctx.user.level = 0;
-    ctx->ctx.user.inside_chunks = false;
     ctx->buf = NULL;
     ctx->head = 0;
     ctx->tail = 0;

+ 14 - 1
src/borg/cache_sync/unpack.h

@@ -89,6 +89,8 @@ typedef struct unpack_user {
         expect_csize,
         /* next thing must be the end of the CLE (array_end) */
         expect_entry_end,
+
+        expect_item_begin
     } expect;
 
     struct {
@@ -108,6 +110,14 @@ typedef int (*execute_fn)(unpack_context *ctx, const char* data, size_t len, siz
         return -1;                                                  \
     }
 
+static inline void unpack_init_user_state(unpack_user *u)
+{
+    u->last_error = NULL;
+    u->level = 0;
+    u->inside_chunks = false;
+    u->expect = expect_item_begin;
+}
+
 static inline int unpack_callback_int64(unpack_user* u, int64_t d)
 {
     switch(u->expect) {
@@ -282,8 +292,11 @@ static inline int unpack_callback_map(unpack_user* u, unsigned int n)
 {
     (void)n;
 
-
     if(u->level == 0) {
+        if(u->expect != expect_item_begin) {
+            set_last_error("Invalid state transition");  /* unreachable */
+            return -1;
+        }
         /* This begins a new Item */
         u->expect = expect_chunks_map_key;
     }

+ 1 - 0
src/borg/cache_sync/unpack_template.h

@@ -42,6 +42,7 @@ static inline void unpack_init(unpack_context* ctx)
     ctx->cs = CS_HEADER;
     ctx->trail = 0;
     ctx->top = 0;
+    unpack_init_user_state(&ctx->user);
 }
 
 #define construct 1