fix CRC values in generated pack index
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/libexec/got-index-pack/got-index-pack.c b/libexec/got-index-pack/got-index-pack.c
index 0418b2d..ddea743 100644
--- a/libexec/got-index-pack/got-index-pack.c
+++ b/libexec/got-index-pack/got-index-pack.c
@@ -231,12 +231,11 @@ object_crc(int packfd, struct got_indexed_object *obj)
size_t n;
ssize_t r;
- obj->crc = 0;
- if (lseek(packfd, obj->off + obj->tslen, SEEK_SET) == -1)
+ if (lseek(packfd, obj->off, SEEK_SET) == -1)
return got_error_from_errno("lseek");
obj->crc = crc32(0L, NULL, 0);
- for (n = obj->len; n > 0; n -= r){
+ for (n = obj->tslen + obj->len; n > 0; n -= r){
r = read(packfd, buf, n > sizeof(buf) ? sizeof(buf) : n);
if (r == -1)
return got_error_from_errno("read");
@@ -416,6 +415,16 @@ update_packidx(int *nlarge, struct got_packidx *packidx, int nobj,
}
}
+static int
+indexed_obj_cmp(const void *pa, const void *pb)
+{
+ struct got_indexed_object *a, *b;
+
+ a = *(struct got_indexed_object **)pa;
+ b = *(struct got_indexed_object **)pb;
+ return got_object_id_cmp(&a->id, &b->id);
+}
+
static const struct got_error *
index_pack(struct got_pack *pack, int idxfd, uint8_t *pack_hash,
struct imsgbuf *ibuf)
@@ -639,6 +648,8 @@ index_pack(struct got_pack *pack, int idxfd, uint8_t *pack_hash,
nobj * SHA1_DIGEST_LENGTH, &ctx);
if (err)
goto done;
+ mergesort(objects, nobj, sizeof(struct got_indexed_object *),
+ indexed_obj_cmp);
for(i = 0; i < nobj; i++){
PUTBE32(buf, objects[i]->crc);
err = hwrite(idxfd, buf, 4, &ctx);