65
65
ARRAY_TYPE(uint32_t) block_offsets;
66
66
ARRAY_TYPE(uint32_t) block_end_indexes;
68
ARRAY_DEFINE(lists, struct uidlist_list);
68
ARRAY(struct uidlist_list) lists;
69
69
uint32_t list_start_idx;
71
71
struct squat_uidlist_file_header build_hdr;
221
221
if (write_size) {
222
222
sizebufp = sizebuf;
223
223
squat_pack_num(&sizebufp, size_value);
224
o_stream_send(output, sizebuf, sizebufp - sizebuf);
224
o_stream_nsend(output, sizebuf, sizebufp - sizebuf);
226
o_stream_send(output, listbuf, listbufp - listbuf);
227
o_stream_send(output, uidbuf, uid_list_len);
226
o_stream_nsend(output, listbuf, listbufp - listbuf);
227
o_stream_nsend(output, uidbuf, uid_list_len);
251
251
if (list->uid_count == 1) {
253
253
squat_pack_num(&bufp, offset);
254
o_stream_send(output, buf, bufp - buf);
254
o_stream_nsend(output, buf, bufp - buf);
255
255
*size_r = (bufp - buf) << 2 | packed_flags;
373
373
if (uidlist->hdr.indexid != uidlist->trie->hdr.indexid) {
374
374
/* see if trie was recreated */
375
squat_trie_refresh(uidlist->trie);
375
(void)squat_trie_refresh(uidlist->trie);
377
377
if (uidlist->hdr.indexid != uidlist->trie->hdr.indexid) {
378
378
squat_uidlist_set_corrupted(uidlist, "wrong indexid");
716
716
struct squat_uidlist_file_header hdr;
718
718
memset(&hdr, 0, sizeof(hdr));
719
o_stream_send(ctx->output, &hdr, sizeof(hdr));
719
o_stream_nsend(ctx->output, &hdr, sizeof(hdr));
721
721
o_stream_cork(ctx->output);
722
722
i_array_init(&ctx->lists, 10240);
756
756
if (align != 0) {
757
757
static char null[sizeof(uint32_t)-1] = { 0, };
759
o_stream_send(output, null, sizeof(uint32_t) - align);
759
o_stream_nsend(output, null, sizeof(uint32_t) - align);
761
761
block_list_offset = output->offset;
764
764
old_block_count = write_old_blocks ? uidlist->cur_block_count : 0;
766
766
block_offset_count = new_block_count + old_block_count;
767
o_stream_send(output, &block_offset_count, sizeof(block_offset_count));
767
o_stream_nsend(output, &block_offset_count, sizeof(block_offset_count));
768
768
/* write end indexes */
769
o_stream_send(output, uidlist->cur_block_end_indexes,
770
old_block_count * sizeof(uint32_t));
771
o_stream_send(output, array_idx(block_end_indexes, 0),
772
new_block_count * sizeof(uint32_t));
769
o_stream_nsend(output, uidlist->cur_block_end_indexes,
770
old_block_count * sizeof(uint32_t));
771
o_stream_nsend(output, array_idx(block_end_indexes, 0),
772
new_block_count * sizeof(uint32_t));
773
773
/* write offsets */
774
o_stream_send(output, uidlist->cur_block_offsets,
775
old_block_count * sizeof(uint32_t));
776
o_stream_send(output, array_idx(block_offsets, 0),
777
new_block_count * sizeof(uint32_t));
778
o_stream_flush(output);
774
o_stream_nsend(output, uidlist->cur_block_offsets,
775
old_block_count * sizeof(uint32_t));
776
o_stream_nsend(output, array_idx(block_offsets, 0),
777
new_block_count * sizeof(uint32_t));
778
(void)o_stream_flush(output);
780
780
/* update header - it's written later when trie is locked */
781
781
ctx->build_hdr.block_list_offset = block_list_offset;
820
820
/* write the full size of the uidlists */
822
822
squat_pack_num(&bufp, block_offset - start_offset);
823
o_stream_send(ctx->output, buf, bufp - buf);
823
o_stream_nsend(ctx->output, buf, bufp - buf);
825
825
/* write the sizes/flags */
826
826
for (j = 0; j < max; j++) {
828
828
squat_pack_num(&bufp, list_sizes[j]);
829
o_stream_send(ctx->output, buf, bufp - buf);
829
o_stream_nsend(ctx->output, buf, bufp - buf);
857
857
if (!ctx->output->closed) {
858
o_stream_seek(ctx->output, 0);
859
o_stream_send(ctx->output,
860
&ctx->build_hdr, sizeof(ctx->build_hdr));
861
o_stream_seek(ctx->output, ctx->build_hdr.used_file_size);
862
o_stream_flush(ctx->output);
858
(void)o_stream_seek(ctx->output, 0);
859
o_stream_nsend(ctx->output,
860
&ctx->build_hdr, sizeof(ctx->build_hdr));
861
(void)o_stream_seek(ctx->output, ctx->build_hdr.used_file_size);
865
if (ctx->output->last_failed_errno != 0) {
866
errno = ctx->output->last_failed_errno;
864
if (o_stream_nfinish(ctx->output) < 0) {
867
865
i_error("write() to %s failed: %m", ctx->uidlist->path);
933
932
o_stream_cork(ctx->output);
935
934
memset(&hdr, 0, sizeof(hdr));
936
o_stream_send(ctx->output, &hdr, sizeof(hdr));
935
o_stream_nsend(ctx->output, &hdr, sizeof(hdr));
938
937
ctx->cur_block_start_offset = ctx->output->offset;
939
938
i_array_init(&ctx->new_block_offsets,
962
961
ended to current offset. write the size of this area. */
964
963
squat_pack_num(&bufp, block_offset - ctx->cur_block_start_offset);
965
o_stream_send(ctx->output, buf, bufp - buf);
964
o_stream_nsend(ctx->output, buf, bufp - buf);
967
966
/* write the sizes/flags */
968
967
for (i = 0; i < ctx->list_idx; i++) {
970
969
squat_pack_num(&bufp, ctx->list_sizes[i]);
971
o_stream_send(ctx->output, buf, bufp - buf);
970
o_stream_nsend(ctx->output, buf, bufp - buf);
973
972
ctx->cur_block_start_offset = ctx->output->offset;
1057
1056
&ctx->new_block_offsets,
1058
1057
&ctx->new_block_end_indexes,
1060
o_stream_seek(ctx->output, 0);
1061
o_stream_send(ctx->output, &ctx->build_ctx->build_hdr,
1062
sizeof(ctx->build_ctx->build_hdr));
1063
o_stream_seek(ctx->output,
1064
ctx->build_ctx->build_hdr.used_file_size);
1065
o_stream_flush(ctx->output);
1059
(void)o_stream_seek(ctx->output, 0);
1060
o_stream_nsend(ctx->output, &ctx->build_ctx->build_hdr,
1061
sizeof(ctx->build_ctx->build_hdr));
1062
(void)o_stream_seek(ctx->output,
1063
ctx->build_ctx->build_hdr.used_file_size);
1067
1065
if (ctx->uidlist->corrupted)
1069
else if (ctx->output->last_failed_errno != 0) {
1070
errno = ctx->output->last_failed_errno;
1067
else if (o_stream_nfinish(ctx->output) < 0) {
1071
1068
i_error("write() to %s failed: %m", temp_path);
1073
1070
} else if (rename(temp_path, ctx->uidlist->path) < 0) {
1082
1079
let it be used for something more useful. */
1083
1080
squat_uidlist_free_from_memory(ctx->uidlist);
1082
o_stream_ignore_last_errors(ctx->output);
1085
1083
o_stream_unref(&ctx->output);
1086
1084
if (close(ctx->fd) < 0)
1087
1085
i_error("close(%s) failed: %m", temp_path);
1179
1177
for (; mask <= 128; mask <<= 1, idx++) {
1180
1178
if ((old_list_idx & mask) != 0) {
1181
squat_uidlist_build_add_uid(ctx,
1179
(void)squat_uidlist_build_add_uid(ctx,
1390
static int uint32_cmp(const void *key, const void *data)
1388
static int uint32_cmp(const uint32_t *key, const uint32_t *data)
1392
const uint32_t *i1 = key, *i2 = data;
1394
return (int)*i1 - (int)*i2;
1390
return (int)*key - (int)*data;
1551
1547
i_array_init(&relative_uids, 128);
1552
1548
i_array_init(&dest_uids, 128);
1553
squat_uidlist_get(uidlist, uid_list_idx, &relative_uids);
1549
if (squat_uidlist_get(uidlist, uid_list_idx, &relative_uids) < 0)
1555
1552
parent_idx = 0;
1556
1553
rel_range = array_get(&relative_uids, &rel_count);
1597
seq_range_array_add(&dest_uids, 0, parent_uid);
1594
seq_range_array_add(&dest_uids, parent_uid);
1598
1595
for (; parent_idx < parent_count; parent_idx++) {
1599
1596
if (parent_range[parent_idx].seq2 <= parent_uid)