comparison src/lib-storage/index/mbox/mbox-sync-rewrite.c @ 2955:d5ee1bbd15f0 HEAD

Fixed mbox corruption in certain situations. Added more asserts to catch similiar problems if there still happens to be any.
author Timo Sirainen <tss@iki.fi>
date Tue, 07 Dec 2004 22:26:00 +0200
parents d1bae4aa3f80
children 8ef9f3d640e0
comparison
equal deleted inserted replaced
2954:9dc7a7b06781 2955:d5ee1bbd15f0
116 116
117 if (ctx->header_first_change > pos) 117 if (ctx->header_first_change > pos)
118 ctx->header_first_change = pos; 118 ctx->header_first_change = pos;
119 ctx->header_last_change = (size_t)-1; 119 ctx->header_last_change = (size_t)-1;
120 120
121 ctx->mail.offset = ctx->hdr_offset + start_pos;
122 ctx->mail.space = (pos - start_pos) + size; 121 ctx->mail.space = (pos - start_pos) + size;
122 ctx->mail.offset = ctx->hdr_offset;
123 if (ctx->mail.space > 0)
124 ctx->mail.offset += start_pos;
123 } 125 }
124 126
125 static void mbox_sync_header_remove_space(struct mbox_sync_mail_context *ctx, 127 static void mbox_sync_header_remove_space(struct mbox_sync_mail_context *ctx,
126 size_t start_pos, size_t *size) 128 size_t start_pos, size_t *size)
127 { 129 {
172 174
173 *size = 0; 175 *size = 0;
174 176
175 if (ctx->mail.space < (off_t)(data_size - last_line_pos)) { 177 if (ctx->mail.space < (off_t)(data_size - last_line_pos)) {
176 ctx->mail.space = data_size - last_line_pos; 178 ctx->mail.space = data_size - last_line_pos;
177 ctx->mail.offset = ctx->hdr_offset + last_line_pos; 179 ctx->mail.offset = ctx->hdr_offset;
180 if (ctx->mail.space > 0)
181 ctx->mail.offset += last_line_pos;
178 } 182 }
179 } 183 }
180 184
181 static void mbox_sync_headers_remove_space(struct mbox_sync_mail_context *ctx, 185 static void mbox_sync_headers_remove_space(struct mbox_sync_mail_context *ctx,
182 size_t size) 186 size_t size)
485 } 489 }
486 mails[idx].offset += move_diff; 490 mails[idx].offset += move_diff;
487 } 491 }
488 492
489 i_assert(move_diff >= 0 || idx == first_nonexpunged_idx); 493 i_assert(move_diff >= 0 || idx == first_nonexpunged_idx);
494 i_assert(next_end_offset <= end_offset);
490 495
491 end_offset = next_end_offset; 496 end_offset = next_end_offset;
492 mails[idx].from_offset += move_diff; 497 mails[idx].from_offset += move_diff;
493 } 498 }
494 499