[dovecot-cvs] dovecot/src/lib-index mail-cache-transaction.c, 1.49.2.5, 1.49.2.6

tss at dovecot.org tss at dovecot.org
Fri Mar 23 05:41:42 EET 2007


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv27914

Modified Files:
      Tag: branch_1_0
	mail-cache-transaction.c 
Log Message:
If we update the fields list in header, it's committed immediately so if the
transaction gets rollbacked, don't overwrite the already committed header.



Index: mail-cache-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-transaction.c,v
retrieving revision 1.49.2.5
retrieving revision 1.49.2.6
diff -u -d -r1.49.2.5 -r1.49.2.6
--- mail-cache-transaction.c	10 Mar 2007 20:58:41 -0000	1.49.2.5
+++ mail-cache-transaction.c	23 Mar 2007 03:41:39 -0000	1.49.2.6
@@ -208,6 +208,34 @@
 	array_append(&ctx->reservations, &res, 1);
 }
 
+static void
+mail_cache_transaction_partial_commit(struct mail_cache_transaction_ctx *ctx,
+				      uint32_t offset, uint32_t size)
+{
+	struct mail_cache_reservation *res;
+	unsigned int i, count;
+
+	if (offset + size == ctx->cache->hdr_copy.used_file_size &&
+	    offset + size == ctx->reserved_space_offset) {
+		i_assert(ctx->reserved_space == 0);
+		ctx->reserved_space_offset = 0;
+	}
+
+	res = array_get_modifyable(&ctx->reservations, &count);
+	for (i = 0; i < count; i++) {
+		if (res[i].offset == offset) {
+			if (res[i].size == size) {
+				array_delete(&ctx->reservations, i, 1);
+			} else {
+				i_assert(res[i].size > size);
+				res[i].offset += size;
+				res[i].size -= size;
+			}
+			break;
+		}
+	}
+}
+
 static int
 mail_cache_transaction_reserve_more(struct mail_cache_transaction_ctx *ctx,
 				    size_t block_size, bool commit)
@@ -675,6 +703,11 @@
 							    &hdr_offset) < 0)
 		ret = -1;
 	else {
+		/* if we rollback the transaction, we must not overwrite this
+		   area because it's already committed after updating the
+		   header offset */
+		mail_cache_transaction_partial_commit(ctx, offset, size);
+
 		/* after it's guaranteed to be in disk, update header offset */
 		offset = mail_index_uint32_to_offset(offset);
 		if (mail_cache_write(cache, &offset, sizeof(offset),



More information about the dovecot-cvs mailing list