[dovecot-cvs] dovecot/src/lib-index mail-cache.c, 1.80.2.7, 1.80.2.8

tss at dovecot.org tss at dovecot.org
Fri Feb 16 10:54:59 UTC 2007


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

Modified Files:
      Tag: branch_1_0
	mail-cache.c 
Log Message:
Allocate cache file's size amount of memory for the file cache so it doesn't
have to grow it constantly while reading the file.



Index: mail-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache.c,v
retrieving revision 1.80.2.7
retrieving revision 1.80.2.8
diff -u -d -r1.80.2.7 -r1.80.2.8
--- mail-cache.c	16 Jan 2007 22:00:16 -0000	1.80.2.7
+++ mail-cache.c	16 Feb 2007 10:54:57 -0000	1.80.2.8
@@ -66,6 +66,21 @@
 	}
 }
 
+static void mail_cache_init_file_cache(struct mail_cache *cache)
+{
+	struct stat st;
+
+	if (cache->file_cache == NULL)
+		return;
+
+	file_cache_set_fd(cache->file_cache, cache->fd);
+
+	if (fstat(cache->fd, &st) < 0)
+		mail_cache_set_syscall_error(cache, "fstat()");
+	else
+		file_cache_set_size(cache->file_cache, st.st_size);
+}
+
 int mail_cache_reopen(struct mail_cache *cache)
 {
 	struct mail_index_view *view;
@@ -89,8 +104,7 @@
 		return -1;
 	}
 
-	if (cache->file_cache != NULL)
-		file_cache_set_fd(cache->file_cache, cache->fd);
+	mail_cache_init_file_cache(cache);
 
 	if (mail_cache_map(cache, 0, 0) < 0)
 		return -1;
@@ -264,8 +278,7 @@
 		return -1;
 	}
 
-	if (cache->file_cache != NULL)
-		file_cache_set_fd(cache->file_cache, cache->fd);
+	mail_cache_init_file_cache(cache);
 
 	if (mail_cache_map(cache, 0, sizeof(struct mail_cache_header)) < 0)
 		return -1;



More information about the dovecot-cvs mailing list