dovecot: mail_cache_reopen(): Don't bother reopening if file is ...

dovecot at dovecot.org dovecot at dovecot.org
Tue Nov 6 18:39:53 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/c601e8cd0ffc
changeset: 6701:c601e8cd0ffc
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Nov 06 18:39:48 2007 +0200
description:
mail_cache_reopen(): Don't bother reopening if file is still the same.

diffstat:

1 file changed, 32 insertions(+), 3 deletions(-)
src/lib-index/mail-cache.c |   35 ++++++++++++++++++++++++++++++++---

diffs (52 lines):

diff -r 16fc51385cd1 -r c601e8cd0ffc src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c	Tue Nov 06 18:27:29 2007 +0200
+++ b/src/lib-index/mail-cache.c	Tue Nov 06 18:39:48 2007 +0200
@@ -91,6 +91,37 @@ static void mail_cache_init_file_cache(s
 		file_cache_set_size(cache->file_cache, st.st_size);
 }
 
+static bool mail_cache_need_reopen(struct mail_cache *cache)
+{
+	struct stat st1, st2;
+
+	if (MAIL_CACHE_IS_UNUSABLE(cache)) {
+		if (cache->need_compress_file_seq != 0) {
+			/* we're waiting for compression */
+			return FALSE;
+		}
+		if (MAIL_INDEX_IS_IN_MEMORY(cache->index)) {
+			/* disabled */
+			return FALSE;
+		}
+	}
+
+	if (cache->fd == -1)
+		return TRUE;
+
+	/* see if the file has changed */
+	if (fstat(cache->fd, &st1) < 0) {
+		mail_cache_set_syscall_error(cache, "fstat()");
+		return TRUE;
+	}
+	if (stat(cache->filepath, &st2) < 0) {
+		mail_cache_set_syscall_error(cache, "stat()");
+		return TRUE;
+	}
+	return st1.st_ino != st2.st_ino ||
+		!CMP_DEV_T(st1.st_dev, st2.st_dev);
+}
+
 int mail_cache_reopen(struct mail_cache *cache)
 {
 	struct mail_index_view *view;
@@ -98,9 +129,7 @@ int mail_cache_reopen(struct mail_cache 
 
 	i_assert(!cache->locked);
 
-	if (MAIL_CACHE_IS_UNUSABLE(cache) &&
-	    (cache->need_compress_file_seq != 0 ||
-	     MAIL_INDEX_IS_IN_MEMORY(cache->index))) {
+	if (!mail_cache_need_reopen(cache)) {
 		/* reopening does no good */
 		return 0;
 	}


More information about the dovecot-cvs mailing list