dovecot: dbox fixes

dovecot at dovecot.org dovecot at dovecot.org
Sat Nov 10 23:40:40 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/f8baedac2417
changeset: 6768:f8baedac2417
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Nov 10 23:40:36 2007 +0200
description:
dbox fixes

diffstat:

6 files changed, 36 insertions(+), 40 deletions(-)
src/lib-storage/index/dbox/dbox-file.c           |   42 +++++++++++-----------
src/lib-storage/index/dbox/dbox-file.h           |    7 ++-
src/lib-storage/index/dbox/dbox-mail.c           |   10 +----
src/lib-storage/index/dbox/dbox-sync-file.c      |    7 +--
src/lib-storage/index/dbox/dbox-sync-rebuild.c   |    8 ++--
src/lib-storage/index/maildir/maildir-keywords.c |    2 -

diffs (208 lines):

diff -r 51793c88b1c7 -r f8baedac2417 src/lib-storage/index/dbox/dbox-file.c
--- a/src/lib-storage/index/dbox/dbox-file.c	Sat Nov 10 23:37:10 2007 +0200
+++ b/src/lib-storage/index/dbox/dbox-file.c	Sat Nov 10 23:40:36 2007 +0200
@@ -570,17 +570,22 @@ int dbox_file_get_mail_stream(struct dbo
 	if (offset == 0)
 		offset = file->file_header_size;
 
-	i_stream_seek(file->input, offset);
-	ret = dbox_file_read_mail_header(file, uid_r, physical_size_r);
-	if (ret <= 0)
-		return ret;
-
-	i_stream_skip(file->input, file->msg_header_size);
+	if (offset != file->cur_offset) {
+		file->cur_offset = offset;
+		i_stream_seek(file->input, offset);
+		ret = dbox_file_read_mail_header(file, &file->cur_uid,
+						 &file->cur_physical_size);
+		if (ret <= 0)
+			return ret;
+	}
 	if (stream_r != NULL) {
+		i_stream_seek(file->input, offset + file->msg_header_size);
 		*stream_r = i_stream_create_limit(file->input,
 						  file->input->v_offset,
-						  *physical_size_r);
-	}
+						  file->cur_physical_size);
+	}
+	*uid_r = file->cur_uid;
+	*physical_size_r = file->cur_physical_size;
 	return 1;
 }
 
@@ -737,8 +742,9 @@ void dbox_file_finish_append(struct dbox
 	file->append_count++;
 }
 
-uoff_t dbox_file_get_metadata_offset(struct dbox_file *file, uoff_t offset,
-				     uoff_t physical_size)
+static uoff_t
+dbox_file_get_metadata_offset(struct dbox_file *file, uoff_t offset,
+			      uoff_t physical_size)
 {
 	if (offset == 0) {
 		if (file->maildir_file)
@@ -844,21 +850,16 @@ int dbox_file_metadata_seek_mail_offset(
 {
 	uoff_t physical_size, metadata_offset;
 	uint32_t uid;
-	bool expunged1, expunged2;
 	int ret;
 
 	ret = dbox_file_get_mail_stream(file, offset, &uid, &physical_size,
-					NULL, &expunged1);
-	if (ret <= 0)
+					NULL, expunged_r);
+	if (ret <= 0 || *expunged_r)
 		return ret;
 
 	metadata_offset =
 		dbox_file_get_metadata_offset(file, offset, physical_size);
-	ret = dbox_file_metadata_seek(file, metadata_offset, &expunged2);
-	if (ret <= 0)
-		return ret;
-	*expunged_r = expunged1 || expunged2;
-	return 1;
+	return dbox_file_metadata_seek(file, metadata_offset, expunged_r);
 }
 
 const char *dbox_file_metadata_get(struct dbox_file *file,
@@ -1128,7 +1129,9 @@ bool dbox_file_lookup(struct dbox_mailbo
 	mail_index_lookup_ext(view, seq, mbox->dbox_ext_id, &data, &expunged);
 	if (expunged)
 		return FALSE;
-	if (data == NULL) {
+	dbox_rec = data;
+
+	if (dbox_rec == NULL || dbox_rec->file_id == 0) {
 		mail_index_lookup_uid(view, seq, &uid);
 		if ((uid & DBOX_FILE_ID_FLAG_UID) != 0) {
 			/* something's broken, we can't handle this high UIDs */
@@ -1137,7 +1140,6 @@ bool dbox_file_lookup(struct dbox_mailbo
 		*file_id_r = DBOX_FILE_ID_FLAG_UID | uid;
 		*offset_r = 0;
 	} else {
-		dbox_rec = data;
 		*file_id_r = dbox_rec->file_id;
 		*offset_r = dbox_rec->offset;
 	}
diff -r 51793c88b1c7 -r f8baedac2417 src/lib-storage/index/dbox/dbox-file.h
--- a/src/lib-storage/index/dbox/dbox-file.h	Sat Nov 10 23:37:10 2007 +0200
+++ b/src/lib-storage/index/dbox/dbox-file.h	Sat Nov 10 23:40:36 2007 +0200
@@ -108,6 +108,10 @@ struct dbox_file {
 	time_t create_time;
 	uoff_t output_stream_offset;
 
+	uoff_t cur_offset;
+	uint32_t cur_uid;
+	uoff_t cur_physical_size;
+
 	char *fname;
 	char *current_path;
 
@@ -181,9 +185,6 @@ void dbox_file_cancel_append(struct dbox
 /* Finish appending the current mail. */
 void dbox_file_finish_append(struct dbox_file *file);
 
-/* Calculate offset to message's metadata. */
-uoff_t dbox_file_get_metadata_offset(struct dbox_file *file, uoff_t offset,
-				     uoff_t physical_size);
 /* Seek to given metadata block. Returns 1 if ok, 0 if file/offset is
    corrupted, -1 if I/O error. If message has already been expunged,
    expunged_r=TRUE and 1 is returned. */
diff -r 51793c88b1c7 -r f8baedac2417 src/lib-storage/index/dbox/dbox-mail.c
--- a/src/lib-storage/index/dbox/dbox-mail.c	Sat Nov 10 23:37:10 2007 +0200
+++ b/src/lib-storage/index/dbox/dbox-mail.c	Sat Nov 10 23:40:36 2007 +0200
@@ -64,20 +64,14 @@ static int
 static int
 dbox_mail_metadata_seek(struct dbox_mail *mail, struct dbox_file **file_r)
 {
-	struct mail *_mail = &mail->imail.mail.mail;
-	uoff_t offset, metadata_offset, physical_size;
+	uoff_t offset;
 	bool expunged;
 	int ret;
 
 	if (dbox_mail_lookup(mail, &offset, file_r) < 0)
 		return -1;
 
-	if (mail_get_physical_size(_mail, &physical_size) < 0)
-		return -1;
-
-	metadata_offset =
-		dbox_file_get_metadata_offset(*file_r, offset, physical_size);
-	ret = dbox_file_metadata_seek(*file_r, metadata_offset, &expunged);
+	ret = dbox_file_metadata_seek_mail_offset(*file_r, offset, &expunged);
 	if (ret <= 0) {
 		if (ret < 0)
 			return -1;
diff -r 51793c88b1c7 -r f8baedac2417 src/lib-storage/index/dbox/dbox-sync-file.c
--- a/src/lib-storage/index/dbox/dbox-sync-file.c	Sat Nov 10 23:37:10 2007 +0200
+++ b/src/lib-storage/index/dbox/dbox-sync-file.c	Sat Nov 10 23:40:36 2007 +0200
@@ -94,7 +94,7 @@ dbox_sync_file_expunge(struct dbox_sync_
 	struct istream *input;
 	struct ostream *output;
 	uint32_t file_id, seq, uid;
-	uoff_t first_offset, offset, physical_size, metadata_offset;
+	uoff_t first_offset, offset, physical_size;
 	const char *out_path;
 	unsigned int i, count;
 	bool expunged;
@@ -151,9 +151,8 @@ dbox_sync_file_expunge(struct dbox_sync_
 			break;
 
 		/* write metadata */
-		metadata_offset = dbox_file_get_metadata_offset(file, offset,
-								physical_size);
-		(void)dbox_file_metadata_seek(file, metadata_offset, &expunged);
+		(void)dbox_file_metadata_seek_mail_offset(file, offset,
+							  &expunged);
 		dbox_sync_update_metadata(ctx, file, entry, seq);
 		if ((ret = dbox_file_metadata_write_to(file, output)) < 0)
 			break;
diff -r 51793c88b1c7 -r f8baedac2417 src/lib-storage/index/dbox/dbox-sync-rebuild.c
--- a/src/lib-storage/index/dbox/dbox-sync-rebuild.c	Sat Nov 10 23:37:10 2007 +0200
+++ b/src/lib-storage/index/dbox/dbox-sync-rebuild.c	Sat Nov 10 23:40:36 2007 +0200
@@ -144,7 +144,7 @@ static int dbox_sync_index_file_next(str
 				     struct dbox_file *file, uoff_t *offset)
 {
 	uint32_t seq, uid;
-	uoff_t metadata_offset, physical_size;
+	uoff_t physical_size;
 	const char *path;
 	bool expunged;
 	int ret;
@@ -185,9 +185,7 @@ static int dbox_sync_index_file_next(str
 		file->last_append_uid = uid;
 	}
 
-	metadata_offset =
-		dbox_file_get_metadata_offset(file, *offset, physical_size);
-	ret = dbox_file_metadata_seek(file, metadata_offset, &expunged);
+	ret = dbox_file_metadata_seek_mail_offset(file, *offset, &expunged);
 	if (ret <= 0) {
 		if (ret < 0)
 			return -1;
@@ -318,6 +316,8 @@ static int dbox_sync_new_maildir(struct 
 	int ret = 0;
 
 	fnames = array_get(&ctx->maildir_new_files, &count);
+	if (count == 0)
+		return 0;
 
 	/* try to give them UIDs beginning from uidlist's next_uid */
 	next_uid = maildir_uidlist_get_next_uid(ctx->maildir_uidlist);
diff -r 51793c88b1c7 -r f8baedac2417 src/lib-storage/index/maildir/maildir-keywords.c
--- a/src/lib-storage/index/maildir/maildir-keywords.c	Sat Nov 10 23:37:10 2007 +0200
+++ b/src/lib-storage/index/maildir/maildir-keywords.c	Sat Nov 10 23:40:36 2007 +0200
@@ -346,7 +346,7 @@ static int maildir_keywords_commit(struc
 
 	mk->synced = FALSE;
 
-	if (!mk->changed)
+	if (!mk->changed || mk->mbox == NULL)
 		return 0;
 
 	/* we could just create the temp file directly, but doing it this


More information about the dovecot-cvs mailing list