[dovecot-cvs] dovecot/src/lib-index/maildir maildir-build.c,1.13,1.14 maildir-index.c,1.12,1.13 maildir-index.h,1.8,1.9 maildir-open.c,1.9,1.10 maildir-rebuild.c,1.6,1.7 maildir-sync.c,1.14,1.15 maildir-update.c,1.11,1.12

cras at procontrol.fi cras at procontrol.fi
Sun Oct 27 08:37:20 EET 2002


Update of /home/cvs/dovecot/src/lib-index/maildir
In directory danu:/tmp/cvs-serv17951/lib-index/maildir

Modified Files:
	maildir-build.c maildir-index.c maildir-index.h maildir-open.c 
	maildir-rebuild.c maildir-sync.c maildir-update.c 
Log Message:
Moved several fields from .imap.index file to .imap.index.data file. Fixed
code so that most of the fields do not need to be set when building index,
allowing the index building to be fast (just readdir()s with maildir). This
still needs some configuration and ability to update the fields whenever it
can grab exclusive lock.

Also fixed SEARCH LARGER, SMALLER and KEYWORD.



Index: maildir-build.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-build.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- maildir-build.c	26 Oct 2002 21:11:30 -0000	1.13
+++ maildir-build.c	27 Oct 2002 06:37:18 -0000	1.14
@@ -11,21 +11,6 @@
 #include <dirent.h>
 #include <sys/stat.h>
 
-static MailIndexRecord *mail_index_record_append_begin(MailIndex *index,
-						       time_t internal_date)
-{
-	MailIndexRecord trec, *rec;
-
-	memset(&trec, 0, sizeof(MailIndexRecord));
-	trec.internal_date = internal_date;
-
-	rec = &trec;
-	if (!index->append_begin(index, &rec))
-		return NULL;
-
-	return rec;
-}
-
 static int maildir_index_append_fd(MailIndex *index, int fd, const char *path,
 				   const char *fname)
 {
@@ -37,24 +22,10 @@
 	i_assert(path != NULL);
 	i_assert(fname != NULL);
 
-	/* check that file size is somewhat reasonable */
-	if (fstat(fd, &st) < 0)
-		return index_file_set_syscall_error(index, path, "fstat()");
-
-	if (st.st_size < 10) {
-		/* This cannot be a mail file - delete it */
-		index_set_error(index, "Invalid size %"PRIuUOFF_T
-				" with mail in %s - deleted", st.st_size, path);
-		if (unlink(path) < 0)
-			index_file_set_syscall_error(index, path, "unlink()");
-		return TRUE;
-	}
-
 	if (!index->set_lock(index, MAIL_LOCK_EXCLUSIVE))
 		return FALSE;
 
-	/* append the file into index */
-	rec = mail_index_record_append_begin(index, st.st_mtime);
+	rec = index->append_begin(index);
 	if (rec == NULL)
 		return FALSE;
 
@@ -64,12 +35,18 @@
 
 	update = index->update_begin(index, rec);
 
+	/* set internal date */
+	if (fd != -1 && fstat(fd, &st) == 0) {
+		index->update_field_raw(update, DATA_HDR_INTERNAL_DATE,
+					&st.st_mtime, sizeof(st.st_mtime));
+	}
+
 	/* set the location */
-	index->update_field(update, FIELD_TYPE_LOCATION, fname,
+	index->update_field(update, DATA_FIELD_LOCATION, fname,
 			    MAILDIR_LOCATION_EXTRA_SPACE);
 
 	/* parse the header and update record's fields */
-	failed = !maildir_record_update(index, update, fd);
+	failed = fd == -1 ? FALSE : !maildir_record_update(index, update, fd);
 
 	if (!index->update_end(update) || failed)
 		return FALSE;

Index: maildir-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-index.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- maildir-index.c	23 Oct 2002 21:07:37 -0000	1.12
+++ maildir-index.c	27 Oct 2002 06:37:18 -0000	1.13
@@ -6,6 +6,7 @@
 #include "mail-index-util.h"
 
 #include <stdio.h>
+#include <sys/stat.h>
 
 extern MailIndex maildir_index;
 
@@ -159,6 +160,33 @@
 	i_free(index);
 }
 
+static time_t maildir_get_internal_date(MailIndex *index, MailIndexRecord *rec)
+{
+	struct stat st;
+	const char *fname;
+	time_t date;
+
+	/* try getting it from cache */
+	date = mail_get_internal_date(index, rec);
+	if (date != (time_t)-1)
+		return date;
+
+	/* stat() gives it */
+	fname = index->lookup_field(index, rec, DATA_FIELD_LOCATION);
+	if (fname == NULL) {
+		index_data_set_corrupted(index->data,
+			"Missing location field for record %u", rec->uid);
+		return (time_t)-1;
+	}
+
+	if (stat(fname, &st) < 0) {
+		index_file_set_syscall_error(index, fname, "stat()");
+		return (time_t)-1;
+	}
+
+	return st.st_mtime;
+}
+
 static int maildir_index_update_flags(MailIndex *index, MailIndexRecord *rec,
 				      unsigned int seq, MailFlags flags,
 				      int external_change)
@@ -168,10 +196,10 @@
 	const char *old_path, *new_path;
 
 	/* we need to update the flags in the file name */
-	old_fname = index->lookup_field(index, rec, FIELD_TYPE_LOCATION);
+	old_fname = index->lookup_field(index, rec, DATA_FIELD_LOCATION);
 	if (old_fname == NULL) {
-		index_data_set_corrupted(index->data, "Missing location field "
-					 "for record %u", rec->uid);
+		index_data_set_corrupted(index->data,
+			"Missing location field for record %u", rec->uid);
 		return FALSE;
 	}
 
@@ -194,7 +222,7 @@
 
 		/* update the filename in index */
 		update = index->update_begin(index, rec);
-		index->update_field(update, FIELD_TYPE_LOCATION, new_fname, 0);
+		index->update_field(update, DATA_FIELD_LOCATION, new_fname, 0);
 
 		if (!index->update_end(update))
 			return FALSE;
@@ -223,6 +251,7 @@
 	mail_index_lookup_field_raw,
 	mail_index_cache_fields_later,
 	maildir_open_mail,
+	maildir_get_internal_date,
 	mail_index_expunge,
 	maildir_index_update_flags,
 	mail_index_append_begin,

Index: maildir-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-index.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- maildir-index.h	26 Oct 2002 21:11:30 -0000	1.8
+++ maildir-index.h	27 Oct 2002 06:37:18 -0000	1.9
@@ -21,7 +21,7 @@
 			    const char *dest_dir);
 
 IBuffer *maildir_open_mail(MailIndex *index, MailIndexRecord *rec,
-			   int *deleted);
+			   time_t *internal_date, int *deleted);
 
 int maildir_record_update(MailIndex *index, MailIndexUpdate *update, int fd);
 

Index: maildir-open.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-open.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- maildir-open.c	20 Oct 2002 00:17:21 -0000	1.9
+++ maildir-open.c	27 Oct 2002 06:37:18 -0000	1.10
@@ -8,10 +8,12 @@
 
 #include <unistd.h>
 #include <fcntl.h>
+#include <sys/stat.h>
 
 IBuffer *maildir_open_mail(MailIndex *index, MailIndexRecord *rec,
-			   int *deleted)
+			   time_t *internal_date, int *deleted)
 {
+	struct stat st;
 	const char *fname, *path;
 	int fd;
 
@@ -23,10 +25,10 @@
 	if (index->inconsistent)
 		return NULL;
 
-	fname = index->lookup_field(index, rec, FIELD_TYPE_LOCATION);
+	fname = index->lookup_field(index, rec, DATA_FIELD_LOCATION);
 	if (fname == NULL) {
-		index_data_set_corrupted(index->data, "Missing location field "
-					 "for record %u", rec->uid);
+		index_data_set_corrupted(index->data,
+			"Missing location field for record %u", rec->uid);
 		return NULL;
 	}
 
@@ -40,6 +42,15 @@
 
 		index_set_error(index, "Error opening mail file %s: %m", path);
 		return NULL;
+	}
+
+	if (internal_date != NULL) {
+		*internal_date = mail_get_internal_date(index, rec);
+
+		if (*internal_date == (time_t)-1) {
+			if (fstat(fd, &st) == 0)
+				*internal_date = st.st_mtime;
+		}
 	}
 
 	return i_buffer_create_mmap(fd, default_pool, MAIL_MMAP_BLOCK_SIZE,

Index: maildir-rebuild.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-rebuild.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- maildir-rebuild.c	20 Oct 2002 02:35:51 -0000	1.6
+++ maildir-rebuild.c	27 Oct 2002 06:37:18 -0000	1.7
@@ -24,7 +24,7 @@
 	index->mmap_used_length = index->header->used_file_size;
 
 	/* require these fields */
-	index->header->cache_fields |= FIELD_TYPE_LOCATION;
+	index->header->cache_fields |= DATA_FIELD_LOCATION;
 
 	/* update indexid, which also means that our state has completely
 	   changed */

Index: maildir-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-sync.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- maildir-sync.c	26 Oct 2002 21:11:30 -0000	1.14
+++ maildir-sync.c	27 Oct 2002 06:37:18 -0000	1.15
@@ -33,7 +33,7 @@
 	update = index->update_begin(index, rec);
 
 	if (fname_changed)
-		index->update_field(update, FIELD_TYPE_LOCATION, fname, 0);
+		index->update_field(update, DATA_FIELD_LOCATION, fname, 0);
 	if (file_changed) {
 		/* file itself changed - reload the header */
 		fd = open(path, O_RDONLY);
@@ -68,6 +68,7 @@
 				    HashTable *files, int check_content_changes)
 {
 	MailIndexRecord *rec;
+	MailIndexDataRecordHeader *data_hdr;
 	struct stat st;
 	const char *fname, *value;
 	char str[1024], *p;
@@ -78,11 +79,11 @@
 
 	rec = index->lookup(index, 1);
 	for (seq = 1; rec != NULL; rec = index->next(index, rec)) {
-		fname = index->lookup_field(index, rec, FIELD_TYPE_LOCATION);
+		fname = index->lookup_field(index, rec, DATA_FIELD_LOCATION);
 		if (fname == NULL) {
 			index_data_set_corrupted(index->data,
-						 "Missing location field for "
-						 "record %u", rec->uid);
+				"Missing location field for record %u",
+				rec->uid);
 			return FALSE;
 		}
 
@@ -116,8 +117,11 @@
 				return FALSE;
 			}
 
-			file_changed = (uoff_t)st.st_size !=
-				rec->body_size + rec->header_size;
+			data_hdr = mail_index_data_lookup_header(index->data,
+								 rec);
+			file_changed = data_hdr != NULL &&
+				(uoff_t)st.st_size !=
+				data_hdr->body_size + data_hdr->header_size;
 		}
 
 		/* changed - update */

Index: maildir-update.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-update.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- maildir-update.c	26 Oct 2002 21:11:30 -0000	1.11
+++ maildir-update.c	27 Oct 2002 06:37:18 -0000	1.12
@@ -7,11 +7,11 @@
 int maildir_record_update(MailIndex *index, MailIndexUpdate *update, int fd)
 {
 	IBuffer *inbuf;
-        MailField cache_fields;
+        MailDataField cache_fields;
 
 	/* don't even bother opening the file if we're not going to do
 	   anything */
-	cache_fields = index->header->cache_fields & ~FIELD_TYPE_LOCATION;
+	cache_fields = index->header->cache_fields & ~DATA_FIELD_LOCATION;
 	if (cache_fields == 0)
 		return TRUE;
 




More information about the dovecot-cvs mailing list