dovecot-2.2: lib-index: Fixed cache file creation race condition.

dovecot at dovecot.org dovecot at dovecot.org
Mon Oct 6 23:36:31 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/6aeb2a7e5303
changeset: 17900:6aeb2a7e5303
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Oct 07 02:35:41 2014 +0300
description:
lib-index: Fixed cache file creation race condition.
If two processes are creating the index files at the same time, don't have
one of them delete the dovecot.index.cache that the other one just created.
This means we never should be calling mail_cache_create(), so it was removed
entirely.

diffstat:

 src/lib-index/mail-cache.c |  12 ------------
 src/lib-index/mail-cache.h |   1 -
 src/lib-index/mail-index.c |   8 ++------
 3 files changed, 2 insertions(+), 19 deletions(-)

diffs (65 lines):

diff -r d6e08d98a170 -r 6aeb2a7e5303 src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c	Tue Oct 07 02:33:03 2014 +0300
+++ b/src/lib-index/mail-cache.c	Tue Oct 07 02:35:41 2014 +0300
@@ -546,18 +546,6 @@
 	return cache;
 }
 
-struct mail_cache *mail_cache_create(struct mail_index *index)
-{
-	struct mail_cache *cache;
-
-	cache = mail_cache_alloc(index);
-	if (!MAIL_INDEX_IS_IN_MEMORY(index)) {
-		if (unlink(cache->filepath) < 0 && errno != ENOENT)
-			mail_cache_set_syscall_error(cache, "unlink()");
-	}
-	return cache;
-}
-
 void mail_cache_free(struct mail_cache **_cache)
 {
 	struct mail_cache *cache = *_cache;
diff -r d6e08d98a170 -r 6aeb2a7e5303 src/lib-index/mail-cache.h
--- a/src/lib-index/mail-cache.h	Tue Oct 07 02:33:03 2014 +0300
+++ b/src/lib-index/mail-cache.h	Tue Oct 07 02:35:41 2014 +0300
@@ -43,7 +43,6 @@
 };
 
 struct mail_cache *mail_cache_open_or_create(struct mail_index *index);
-struct mail_cache *mail_cache_create(struct mail_index *index);
 void mail_cache_free(struct mail_cache **cache);
 
 /* Register fields. fields[].idx is updated to contain field index.
diff -r d6e08d98a170 -r 6aeb2a7e5303 src/lib-index/mail-index.c
--- a/src/lib-index/mail-index.c	Tue Oct 07 02:33:03 2014 +0300
+++ b/src/lib-index/mail-index.c	Tue Oct 07 02:35:41 2014 +0300
@@ -474,7 +474,6 @@
 				 enum mail_index_open_flags flags)
 {
 	int ret;
-	bool created = FALSE;
 
 	ret = mail_transaction_log_open(index->log);
 	if (ret == 0) {
@@ -501,7 +500,6 @@
 			index->map->hdr.indexid = index->indexid;
 		}
 		index->initial_create = FALSE;
-		created = TRUE;
 	}
 	if (ret >= 0) {
 		ret = index->map != NULL ? 1 : mail_index_try_open(index);
@@ -525,10 +523,8 @@
 			return -1;
 	}
 
-	if (index->cache == NULL) {
-		index->cache = created ? mail_cache_create(index) :
-			mail_cache_open_or_create(index);
-	}
+	if (index->cache == NULL)
+		index->cache = mail_cache_open_or_create(index);
 	return 1;
 }
 


More information about the dovecot-cvs mailing list