Fix IndexItem->valid so it is either -1 (failed), 0 (missing) or 1 (good)
authorJonathan Dieter <jdieter@gmail.com>
Tue, 5 Jun 2018 11:09:35 +0000 (14:09 +0300)
committerJonathan Dieter <jdieter@gmail.com>
Tue, 5 Jun 2018 11:09:35 +0000 (14:09 +0300)
Signed-off-by: Jonathan Dieter <jdieter@gmail.com>
src/lib/index/index_read.c

index 431f09c00dd4bd64ce27e4e122d92b897e3b62b8..8dc99fd57816ec9d2dcf001c8258681114f43ff6 100644 (file)
 
 #include "zck_private.h"
 
+#define VALIDATE(f)     if(!f) { \
+                            zck_log(ZCK_LOG_ERROR, "zckCtx not initialized\n"); \
+                            return False; \
+                        }
+
 int zck_index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
+    VALIDATE(zck);
     size_t length = 0;
 
-
     /* Read and configure hash type */
     int hash_type;
     if(!compint_to_int(&hash_type, data + length, &length, max_length))
@@ -88,7 +93,7 @@ int zck_index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
             return False;
         new->length = chunk_length;
 
-        new->valid = False;
+        new->valid = 0;
         idx_loc += new->comp_length;
         zck->index.length = idx_loc;
 
@@ -102,3 +107,35 @@ int zck_index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
     zck->index_string = NULL;
     return True;
 }
+
+int PUBLIC zck_missing_chunks(zckCtx *zck) {
+    if(zck == NULL) {
+        zck_log(ZCK_LOG_ERROR, "zckCtx not initialized\n");
+        return -1;
+    }
+    int missing = 0;
+    for(zckIndexItem *idx = zck->index.first; idx; idx=idx->next)
+        if(idx->valid == 0)
+            missing++;
+    return missing;
+}
+
+int PUBLIC zck_has_failed_chunks(zckCtx *zck) {
+    if(zck == NULL) {
+        zck_log(ZCK_LOG_ERROR, "zckCtx not initialized\n");
+        return -1;
+    }
+    int failed = 0;
+    for(zckIndexItem *idx = zck->index.first; idx; idx=idx->next)
+        if(idx->valid == -1)
+            failed++;
+    return failed;
+}
+
+int PUBLIC zck_reset_failed_chunks(zckCtx *zck) {
+    VALIDATE(zck);
+    for(zckIndexItem *idx = zck->index.first; idx; idx=idx->next)
+        if(idx->valid == -1)
+            idx->valid = 0;
+    return True;
+}