changeset 2420:90f25ed2dcef HEAD

rollback: don't lock file if we don't need to
author Timo Sirainen <tss@iki.fi>
date Sun, 15 Aug 2004 05:54:47 +0300
parents ba29613cbb19
children d141e1bfdd63
files src/lib-index/mail-cache-transaction.c
diffstat 1 files changed, 19 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-cache-transaction.c	Sun Aug 15 05:50:29 2004 +0300
+++ b/src/lib-index/mail-cache-transaction.c	Sun Aug 15 05:54:47 2004 +0300
@@ -480,24 +480,28 @@
 	const uint32_t *buf;
 	size_t size;
 
-	if (mail_cache_lock(cache) > 0) {
-		mail_cache_transaction_free_space(ctx);
+	buf = buffer_get_data(ctx->reservations, &size);
+	i_assert(size % sizeof(uint32_t)*2 == 0);
+	size /= sizeof(*buf);
 
-		buf = buffer_get_data(ctx->reservations, &size);
-		i_assert(size % sizeof(uint32_t)*2 == 0);
-		size /= sizeof(*buf);
+	if (ctx->reserved_space > 0 || size > 0) {
+		if (mail_cache_lock(cache) > 0) {
+			mail_cache_transaction_free_space(ctx);
 
-		if (size > 0) {
-			/* free flushed data as well. do it from end to
-			   beginning so we have a better chance of updating
-			   used_file_size instead of adding holes */
-			do {
-				size -= 2;
-				mail_cache_free_space(ctx->cache, buf[size],
-						      buf[size+1]);
-			} while (size > 0);
+			if (size > 0) {
+				/* free flushed data as well. do it from end to
+				   beginning so we have a better chance of
+				   updating used_file_size instead of adding
+				   holes */
+				do {
+					size -= 2;
+					mail_cache_free_space(ctx->cache,
+							      buf[size],
+							      buf[size+1]);
+				} while (size > 0);
+			}
+			mail_cache_unlock(cache);
 		}
-		mail_cache_unlock(cache);
 	}
 
 	mail_cache_transaction_free(ctx);