[dovecot-cvs] dovecot/src/lib-index mail-cache-transaction.c, 1.55, 1.56

tss at dovecot.org tss at dovecot.org
Thu Feb 1 22:23:23 UTC 2007


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

Modified Files:
	mail-cache-transaction.c 
Log Message:
If cache file wasn't opened yet when flushing a transaction, the changes
weren't written to the file. Also fixes a "invalid record size" bug which
could have happened when transaction flush failed.



Index: mail-cache-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-transaction.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- mail-cache-transaction.c	17 Dec 2006 16:35:32 -0000	1.55
+++ mail-cache-transaction.c	1 Feb 2007 22:23:18 -0000	1.56
@@ -469,6 +469,11 @@
 		buffer_set_used_size(ctx->cache_data, ctx->prev_pos);
 	}
 
+	if (ctx->cache_file_seq == 0) {
+		if ((ret = mail_cache_transaction_lock(ctx)) <= 0)
+			return ret;
+	}
+
 	if (ctx->cache_file_seq != ctx->cache->hdr->file_seq) {
 		/* cache file reopened - need to abort */
 		mail_cache_transaction_reset(ctx);
@@ -488,7 +493,7 @@
 						       max_size, &write_offset,
 						       &max_size, commit);
 		if (ret <= 0) {
-			/* nothing to write / error / cache file reopened */
+			/* error / couldn't lock / cache file reopened */
 			return ret;
 		}
 
@@ -545,7 +550,7 @@
 		data = buffer_get_modifiable_data(ctx->cache_data, &size);
 		rec = PTR_OFFSET(data, ctx->prev_pos);
 		rec->size = size - ctx->prev_pos;
-		i_assert(rec->size != 0);
+		i_assert(rec->size > sizeof(*rec));
 
 		array_append(&ctx->cache_data_seq, &ctx->prev_seq, 1);
 		ctx->prev_pos = size;
@@ -737,8 +742,13 @@
 		   cache file had been compressed and was reopened, return
 		   without adding the cached data since cache_data buffer
 		   doesn't contain the cache_rec anymore. */
-		if (mail_cache_transaction_flush(ctx) <= 0)
+		if (mail_cache_transaction_flush(ctx) <= 0) {
+			/* make sure the transaction is reset, so we don't
+			   constantly try to flush for each call to this
+			   function */
+			mail_cache_transaction_reset(ctx);
 			return;
+		}
 	}
 
 	buffer_append(ctx->cache_data, &file_field, sizeof(file_field));



More information about the dovecot-cvs mailing list