changeset 1362:085c5b7a69ad HEAD

If we don't want to precache anything, don't open the file at all when building index.
author Timo Sirainen <tss@iki.fi>
date Wed, 16 Apr 2003 16:57:21 +0300
parents dc2163fafa70
children 383e4b9e347c
files src/lib-index/maildir/Makefile.am src/lib-index/maildir/maildir-build.c src/lib-index/maildir/maildir-index.h src/lib-index/maildir/maildir-update.c
diffstat 4 files changed, 27 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/maildir/Makefile.am	Wed Apr 16 16:38:17 2003 +0300
+++ b/src/lib-index/maildir/Makefile.am	Wed Apr 16 16:57:21 2003 +0300
@@ -13,8 +13,7 @@
 	maildir-open.c \
 	maildir-rebuild.c \
 	maildir-sync.c \
-	maildir-uidlist.c \
-	maildir-update.c
+	maildir-uidlist.c
 
 noinst_HEADERS = \
 	maildir-index.h \
--- a/src/lib-index/maildir/maildir-build.c	Wed Apr 16 16:38:17 2003 +0300
+++ b/src/lib-index/maildir/maildir-build.c	Wed Apr 16 16:57:21 2003 +0300
@@ -1,6 +1,7 @@
 /* Copyright (C) 2002 Timo Sirainen */
 
 #include "lib.h"
+#include "istream.h"
 #include "str.h"
 #include "maildir-index.h"
 #include "mail-index-data.h"
@@ -12,6 +13,27 @@
 #include <dirent.h>
 #include <sys/stat.h>
 
+static int maildir_record_update(struct mail_index *index,
+				 struct mail_index_update *update, int fd)
+{
+	struct istream *input;
+        enum mail_data_field cache_fields;
+
+	if (index->mail_read_mmaped) {
+		input = i_stream_create_mmap(fd, system_pool,
+					     MAIL_MMAP_BLOCK_SIZE, 0, 0, FALSE);
+	} else {
+		input = i_stream_create_file(fd, system_pool,
+					     MAIL_READ_BLOCK_SIZE, FALSE);
+	}
+
+	cache_fields = index->header->cache_fields & ~DATA_FIELD_LOCATION;
+	mail_index_update_headers(update, input, cache_fields, NULL, NULL);
+
+	i_stream_unref(input);
+	return TRUE;
+}
+
 static int maildir_index_append_fd(struct mail_index *index,
 				   int fd, const char *fname)
 {
@@ -83,8 +105,10 @@
 
 	i_assert(index->lock_type != MAIL_LOCK_SHARED);
 
-	i_assert(dir != NULL);
-	i_assert(fname != NULL);
+	if ((index->header->cache_fields & ~DATA_FIELD_LOCATION) == 0) {
+		/* nothing cached, don't bother opening the file */
+		return maildir_index_append_fd(index, -1, fname);
+	}
 
 	path = t_strconcat(dir, "/", fname, NULL);
 	fd = open(path, O_RDONLY);
--- a/src/lib-index/maildir/maildir-index.h	Wed Apr 16 16:38:17 2003 +0300
+++ b/src/lib-index/maildir/maildir-index.h	Wed Apr 16 16:57:21 2003 +0300
@@ -35,9 +35,6 @@
 				  struct mail_index_record *rec,
 				  time_t *internal_date, int *deleted);
 
-int maildir_record_update(struct mail_index *index,
-			  struct mail_index_update *update, int fd);
-
 void maildir_clean_tmp(const char *dir);
 
 #endif
--- a/src/lib-index/maildir/maildir-update.c	Wed Apr 16 16:38:17 2003 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-/* Copyright (C) 2002 Timo Sirainen */
-
-#include "lib.h"
-#include "istream.h"
-#include "maildir-index.h"
-
-int maildir_record_update(struct mail_index *index,
-			  struct mail_index_update *update, int fd)
-{
-	struct istream *input;
-        enum mail_data_field cache_fields;
-
-	/* don't even bother opening the file if we're not going to do
-	   anything */
-	cache_fields = index->header->cache_fields & ~DATA_FIELD_LOCATION;
-	if (cache_fields == 0)
-		return TRUE;
-
-	t_push();
-	if (index->mail_read_mmaped) {
-		input = i_stream_create_mmap(fd, data_stack_pool,
-					     MAIL_MMAP_BLOCK_SIZE, 0, 0, FALSE);
-	} else {
-		input = i_stream_create_file(fd, data_stack_pool,
-					     MAIL_READ_BLOCK_SIZE, FALSE);
-	}
-	mail_index_update_headers(update, input, cache_fields, NULL, NULL);
-	i_stream_unref(input);
-	t_pop();
-	return TRUE;
-}