[dovecot-cvs] dovecot/src/lib-storage/index/dbox dbox-save.c, 1.12, 1.13 dbox-uidlist.c, 1.30, 1.31 dbox-uidlist.h, 1.5, 1.6

cras at dovecot.org cras at dovecot.org
Thu Jun 8 21:21:14 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib-storage/index/dbox
In directory talvi:/tmp/cvs-serv11518

Modified Files:
	dbox-save.c dbox-uidlist.c dbox-uidlist.h 
Log Message:
If mail's size is known beforehand, select the dbox file so that the saving    
won't grow file larger than dbox_rotate_size.



Index: dbox-save.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-save.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- dbox-save.c	8 Jun 2006 17:14:27 -0000	1.12
+++ dbox-save.c	8 Jun 2006 18:21:12 -0000	1.13
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "array.h"
 #include "ioloop.h"
+#include "istream.h"
 #include "hex-dec.h"
 #include "write-full.h"
 #include "ostream.h"
@@ -108,6 +109,7 @@
 	struct dbox_mailbox *mbox = (struct dbox_mailbox *)t->ictx.ibox;
 	struct dbox_save_context *ctx = t->save_ctx;
 	struct dbox_mail_header hdr;
+	const struct stat *st;
 	buffer_t *file_keywords = NULL;
 	enum mail_flags save_flags;
 	unsigned int i, pos, left;
@@ -139,7 +141,13 @@
 	}
 	ctx->input = input;
 
-	if (dbox_uidlist_append_locked(ctx->append_ctx, &ctx->file) < 0) {
+	/* get the size of the mail to be saved, if possible */
+	st = i_stream_stat(input, TRUE);
+	if (st != NULL && st->st_size == -1)
+		st = NULL;
+
+	if (dbox_uidlist_append_locked(ctx->append_ctx, &ctx->file,
+				       st != NULL ? st->st_size : 0) < 0) {
 		ctx->failed = TRUE;
 		return -1;
 	}

Index: dbox-uidlist.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-uidlist.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- dbox-uidlist.c	8 Jun 2006 17:14:00 -0000	1.30
+++ dbox-uidlist.c	8 Jun 2006 18:21:12 -0000	1.31
@@ -973,7 +973,8 @@
 
 static int
 dbox_file_append_lock(struct dbox_uidlist_append_ctx *ctx, string_t *path,
-		      uint32_t *file_seq_r, struct dbox_uidlist_entry **entry_r,
+		      uoff_t mail_size, uint32_t *file_seq_r,
+		      struct dbox_uidlist_entry **entry_r,
 		      struct dotlock **dotlock_r, bool *existing_r)
 {
 	struct dbox_mailbox *mbox = ctx->uidlist->mbox;
@@ -988,7 +989,8 @@
 		*existing_r = FALSE;
 		for (; i < count; i++) {
 			if (DBOX_CAN_APPEND(ctx, entries[i]->create_time,
-					    entries[i]->file_size) &&
+					    entries[i]->file_size +
+					    mail_size) &&
 			    !dbox_uidlist_files_lookup(ctx,
 						       entries[i]->file_seq)) {
 				*existing_r = TRUE;
@@ -1054,7 +1056,7 @@
 }
 
 int dbox_uidlist_append_locked(struct dbox_uidlist_append_ctx *ctx,
-			       struct dbox_file **file_r)
+			       struct dbox_file **file_r, uoff_t mail_size)
 {
 	struct dbox_save_file *const *files, *save_file;
 	struct dbox_uidlist_entry *entry;
@@ -1072,7 +1074,8 @@
 	files = array_get(&ctx->files, &count);
 	for (i = 0; i < count; i++) {
 		if (DBOX_CAN_APPEND(ctx, files[i]->file->create_time,
-				    files[i]->file->append_offset)) {
+				    files[i]->file->append_offset +
+				    mail_size)) {
 			if (dbox_reopen_file(ctx, files[i]) < 0)
 				return -1;
 
@@ -1088,7 +1091,7 @@
 	do {
 		if (dotlock != NULL)
 			file_dotlock_delete(&dotlock);
-		if (dbox_file_append_lock(ctx, path, &file_seq,
+		if (dbox_file_append_lock(ctx, path, mail_size, &file_seq,
 					  &entry, &dotlock, &existing) < 0)
 			return -1;
 	} while ((ret = dbox_file_append(ctx, str_c(path), entry,

Index: dbox-uidlist.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-uidlist.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- dbox-uidlist.h	31 Mar 2006 21:21:20 -0000	1.5
+++ dbox-uidlist.h	8 Jun 2006 18:21:12 -0000	1.6
@@ -31,7 +31,7 @@
    Returns -1 if failed, 0 if ok. If new file is created, the file's header is
    already appended. */
 int dbox_uidlist_append_locked(struct dbox_uidlist_append_ctx *ctx,
-			       struct dbox_file **file_r);
+			       struct dbox_file **file_r, uoff_t mail_size);
 void dbox_uidlist_append_finish_mail(struct dbox_uidlist_append_ctx *ctx,
 				     struct dbox_file *file);
 



More information about the dovecot-cvs mailing list