[dovecot-cvs] dovecot/src/lib-index mail-cache-lookup.c, 1.34, 1.35 mail-cache-private.h, 1.31, 1.32 mail-cache.c, 1.86, 1.87

tss at dovecot.org tss at dovecot.org
Fri Oct 13 16:19:58 UTC 2006


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

Modified Files:
	mail-cache-lookup.c mail-cache-private.h mail-cache.c 
Log Message:
Delay opening the cache file until it's actually needed.



Index: mail-cache-lookup.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-lookup.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- mail-cache-lookup.c	28 Jun 2006 13:10:38 -0000	1.34
+++ mail-cache-lookup.c	13 Oct 2006 15:19:54 -0000	1.35
@@ -185,6 +185,9 @@
 	uint32_t offset;
 	int ret;
 
+	if (!view->cache->opened)
+		(void)mail_cache_open_and_verify(view->cache);
+
         if (MAIL_CACHE_IS_UNUSABLE(view->cache))
 		return 0;
 
@@ -269,6 +272,9 @@
 	i_assert(seq > 0);
 	i_assert(field < view->cache->fields_count);
 
+	if (!view->cache->opened)
+		(void)mail_cache_open_and_verify(view->cache);
+
 	file_field = view->cache->field_file_map[field];
 	if (file_field == (uint32_t)-1)
 		return 0;

Index: mail-cache-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-private.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- mail-cache-private.h	11 Jul 2006 16:02:43 -0000	1.31
+++ mail-cache-private.h	13 Oct 2006 15:19:55 -0000	1.32
@@ -147,6 +147,7 @@
 	unsigned int *file_field_map;
 	unsigned int file_fields_count;
 
+	unsigned int opened:1;
 	unsigned int locked:1;
 	unsigned int hdr_modified:1;
 	unsigned int field_header_write_pending:1;
@@ -176,6 +177,8 @@
 					  const void *data, size_t data_size,
 					  void *context);
 
+int mail_cache_open_and_verify(struct mail_cache *cache);
+
 /* Explicitly lock the cache file. Returns -1 if error, 1 if ok, 0 if we
    couldn't lock */
 int mail_cache_lock(struct mail_cache *cache);

Index: mail-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -d -r1.86 -r1.87
--- mail-cache.c	13 Oct 2006 15:02:46 -0000	1.86
+++ mail-cache.c	13 Oct 2006 15:19:55 -0000	1.87
@@ -251,8 +251,10 @@
 	return 0;
 }
 
-static int mail_cache_open_and_verify(struct mail_cache *cache)
+static int mail_cache_try_open(struct mail_cache *cache)
 {
+	cache->opened = TRUE;
+
 	if (MAIL_INDEX_IS_IN_MEMORY(cache->index))
 		return 0;
 
@@ -273,7 +275,22 @@
 	if (mail_cache_map(cache, 0, sizeof(struct mail_cache_header)) < 0)
 		return -1;
 
-	return mail_cache_header_fields_read(cache);
+	return 1;
+}
+
+int mail_cache_open_and_verify(struct mail_cache *cache)
+{
+	int ret;
+
+	ret = mail_cache_try_open(cache);
+	if (ret > 0)
+		ret = mail_cache_header_fields_read(cache);
+	if (ret < 0) {
+		/* failed for some reason - doesn't really matter,
+		   it's disabled for now. */
+		mail_cache_file_close(cache);
+	}
+	return ret;
 }
 
 static struct mail_cache *mail_cache_alloc(struct mail_index *index)
@@ -323,11 +340,6 @@
 	struct mail_cache *cache;
 
 	cache = mail_cache_alloc(index);
-	if (mail_cache_open_and_verify(cache) < 0) {
-		/* failed for some reason - doesn't really matter,
-		   it's disabled for now. */
-		mail_cache_file_close(cache);
-	}
 	return cache;
 }
 
@@ -336,6 +348,7 @@
 	struct mail_cache *cache;
 
 	cache = mail_cache_alloc(index);
+	cache->opened = TRUE;
 	cache->need_compress_file_seq = (uint32_t)-1;
 	return cache;
 }
@@ -389,6 +402,9 @@
 
 	i_assert(!cache->locked);
 
+	if (!cache->opened)
+		(void)mail_cache_open_and_verify(cache);
+
 	if (MAIL_CACHE_IS_UNUSABLE(cache) ||
 	    MAIL_INDEX_IS_IN_MEMORY(cache->index))
 		return 0;



More information about the dovecot-cvs mailing list