dovecot-1.1: dbox: Don't write message UID to u.* files' header,...

dovecot at dovecot.org dovecot at dovecot.org
Sun May 25 02:52:44 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/cf924043234d
changeset: 7542:cf924043234d
user:      Timo Sirainen <tss at iki.fi>
date:      Sun May 25 02:52:39 2008 +0300
description:
dbox: Don't write message UID to u.* files' header, since the filename
itself specifies the UID already. When reading u.* files ignore the UID
field completely. This would allow hard linking u.* files, but the metadata
will then contain only a single mailbox's flags+keywords.

diffstat:

2 files changed, 35 insertions(+), 24 deletions(-)
src/lib-storage/index/dbox/dbox-file.c |    5 ++
src/lib-storage/index/dbox/dbox-save.c |   54 ++++++++++++++++++--------------

diffs (107 lines):

diff -r a2a199667c05 -r cf924043234d src/lib-storage/index/dbox/dbox-file.c
--- a/src/lib-storage/index/dbox/dbox-file.c	Sun May 25 02:50:23 2008 +0300
+++ b/src/lib-storage/index/dbox/dbox-file.c	Sun May 25 02:52:39 2008 +0300
@@ -600,7 +600,10 @@ static int dbox_file_read_mail_header(st
 		return 0;
 	}
 
-	*uid_r = hex2dec(hdr.uid_hex, sizeof(hdr.uid_hex));
+	/* Ignore the UID header with UID files */
+	*uid_r = (file->file_id & DBOX_FILE_ID_FLAG_UID) != 0 ?
+		(file->file_id & ~DBOX_FILE_ID_FLAG_UID) :
+		hex2dec(hdr.uid_hex, sizeof(hdr.uid_hex));
 	*physical_size_r = hex2dec(hdr.message_size_hex,
 				   sizeof(hdr.message_size_hex));
 	return 1;
diff -r a2a199667c05 -r cf924043234d src/lib-storage/index/dbox/dbox-save.c
--- a/src/lib-storage/index/dbox/dbox-save.c	Sun May 25 02:50:23 2008 +0300
+++ b/src/lib-storage/index/dbox/dbox-save.c	Sun May 25 02:52:39 2008 +0300
@@ -218,6 +218,23 @@ static void dbox_save_write_metadata(str
 	o_stream_send(ctx->cur_output, "\n", 1);
 }
 
+static int dbox_save_mail_write_header(struct dbox_save_mail *mail)
+{
+	struct dbox_message_header dbox_msg_hdr;
+
+	i_assert(mail->file->msg_header_size == sizeof(dbox_msg_hdr));
+
+	mail->file->last_append_uid = mail->uid;
+	dbox_msg_header_fill(&dbox_msg_hdr, mail->uid, mail->message_size);
+
+	if (pwrite_full(mail->file->fd, &dbox_msg_hdr,
+			sizeof(dbox_msg_hdr), mail->append_offset) < 0) {
+		dbox_file_set_syscall_error(mail->file, "write");
+		return -1;
+	}
+	return 0;
+}
+
 int dbox_save_finish(struct mail_save_context *_ctx)
 {
 	struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
@@ -250,12 +267,6 @@ int dbox_save_finish(struct mail_save_co
 	i_stream_unref(&ctx->input);
 
 	count = array_count(&ctx->mails);
-	if (count >= ctx->mbox->max_open_files) {
-		/* too many open files, close one of them */
-		save_mail = array_idx_modifiable(&ctx->mails, count -
-						 ctx->mbox->max_open_files);
-		dbox_file_close(save_mail->file);
-	}
 	save_mail = array_idx_modifiable(&ctx->mails, count - 1);
 	if (ctx->failed) {
 		dbox_file_cancel_append(save_mail->file,
@@ -267,6 +278,12 @@ int dbox_save_finish(struct mail_save_co
 		dbox_file_finish_append(save_mail->file);
 		save_mail->message_size = offset - save_mail->append_offset -
 			save_mail->file->msg_header_size;
+
+		if (save_mail->file->append_count == 1 &&
+		    !dbox_file_can_append(save_mail->file, 0)) {
+			dbox_save_mail_write_header(save_mail);
+			dbox_file_close(save_mail->file);
+		}
 		return 0;
 	}
 }
@@ -277,23 +294,6 @@ void dbox_save_cancel(struct mail_save_c
 
 	ctx->failed = TRUE;
 	(void)dbox_save_finish(_ctx);
-}
-
-static int dbox_save_mail_write_header(struct dbox_save_mail *mail)
-{
-	struct dbox_message_header dbox_msg_hdr;
-
-	i_assert(mail->file->msg_header_size == sizeof(dbox_msg_hdr));
-
-	mail->file->last_append_uid = mail->uid;
-	dbox_msg_header_fill(&dbox_msg_hdr, mail->uid, mail->message_size);
-
-	if (pwrite_full(mail->file->fd, &dbox_msg_hdr,
-			sizeof(dbox_msg_hdr), mail->append_offset) < 0) {
-		dbox_file_set_syscall_error(mail->file, "write");
-		return -1;
-	}
-	return 0;
 }
 
 static int
@@ -359,6 +359,14 @@ static int dbox_save_commit(struct dbox_
 	/* update headers */
 	qsort(mails, count, sizeof(*mails), dbox_save_mail_file_cmp);
 	for (i = 0; i < count; i++) {
+		mails[i].file->last_append_uid = mails[i].uid;
+		if (mails[i].file->append_count == 1 &&
+		    !dbox_file_can_append(mails[i].file, 0)) {
+			/* UID file - there's no need to write it to the
+			   header */
+			continue;
+		}
+
 		if (dbox_file_open_if_needed(mails[i].file) < 0 ||
 		    dbox_save_mail_write_header(&mails[i]) < 0) {
 			ret = -1;


More information about the dovecot-cvs mailing list