[dovecot-cvs] dovecot/src/lib-index mail-cache-compress.c, 1.42.2.2, 1.42.2.3

tss at dovecot.org tss at dovecot.org
Fri Dec 29 00:23:35 UTC 2006


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

Modified Files:
      Tag: branch_1_0
	mail-cache-compress.c 
Log Message:
If cache compressing notices that it was compressed after locking, we left
the cache file locked. Also in case of errors we left it locked.



Index: mail-cache-compress.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-compress.c,v
retrieving revision 1.42.2.2
retrieving revision 1.42.2.3
diff -u -d -r1.42.2.2 -r1.42.2.3
--- mail-cache-compress.c	12 Nov 2006 18:02:14 -0000	1.42.2.2
+++ mail-cache-compress.c	29 Dec 2006 00:23:29 -0000	1.42.2.3
@@ -273,7 +273,8 @@
 }
 
 static int mail_cache_compress_locked(struct mail_cache *cache,
-				      struct mail_index_view *view)
+				      struct mail_index_view *view,
+				      bool *unlock)
 {
 	struct dotlock *dotlock;
         mode_t old_mask;
@@ -300,6 +301,12 @@
 		/* was just compressed, forget this */
 		cache->need_compress_file_seq = 0;
 		file_dotlock_delete(&dotlock);
+
+		if (*unlock) {
+			(void)mail_cache_unlock(cache);
+			*unlock = FALSE;
+		}
+
 		return mail_cache_reopen(cache);
 	}
 
@@ -328,6 +335,11 @@
 		return -1;
 	}
 
+	if (*unlock) {
+		(void)mail_cache_unlock(cache);
+		*unlock = FALSE;
+	}
+
 	mail_cache_file_close(cache);
 	cache->fd = fd;
 
@@ -345,6 +357,7 @@
 
 int mail_cache_compress(struct mail_cache *cache, struct mail_index_view *view)
 {
+	bool unlock = FALSE;
 	int ret;
 
 	if (MAIL_INDEX_IS_IN_MEMORY(cache->index))
@@ -353,7 +366,7 @@
 	if (cache->index->lock_method == MAIL_INDEX_LOCK_DOTLOCK) {
 		/* we're using dotlocking, cache file creation itself creates
 		   the dotlock file we need. */
-		return mail_cache_compress_locked(cache, view);
+		return mail_cache_compress_locked(cache, view, &unlock);
 	}
 
 	switch (mail_cache_lock(cache)) {
@@ -362,12 +375,15 @@
 	case 0:
 		/* couldn't lock, either it's broken or doesn't exist.
 		   just start creating it. */
-		return mail_cache_compress_locked(cache, view);
+		return mail_cache_compress_locked(cache, view, &unlock);
 	default:
 		/* locking succeeded. */
-		ret = mail_cache_compress_locked(cache, view);
-		if (mail_cache_unlock(cache) < 0)
-			ret = -1;
+		unlock = TRUE;
+		ret = mail_cache_compress_locked(cache, view, &unlock);
+		if (unlock) {
+			if (mail_cache_unlock(cache) < 0)
+				ret = -1;
+		}
 		return ret;
 	}
 }



More information about the dovecot-cvs mailing list