diff src/lib-storage/index/dbox/dbox-uidlist.c @ 4109:988a8ef1deea HEAD

Some fixes to get dbox code working better. Still needs some work though..
author Timo Sirainen <tss@iki.fi>
date Thu, 30 Mar 2006 13:31:28 +0300
parents 71b8faa84ec6
children d1c27abc6ebc
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-uidlist.c	Mon Mar 27 15:54:24 2006 +0300
+++ b/src/lib-storage/index/dbox/dbox-uidlist.c	Thu Mar 30 13:31:28 2006 +0300
@@ -891,6 +891,7 @@
 	   it's not completely trustworthy though. */
 	str = str_new(ctx->pool, 64);
 	entries = array_get(&ctx->uidlist->entries, &count);
+__again:
 	for (i = 0;; i++) {
                 file_seq = 0; 
 		for (; i < count; i++) {
@@ -930,11 +931,9 @@
 		/* lock already exists, try next file */
 	}
 
-	save_file = p_new(ctx->pool, struct dbox_save_file, 1);
-	save_file->file = file = p_new(ctx->pool, struct dbox_file, 1);
-        save_file->dotlock = dotlock;
+	file = i_new(struct dbox_file, 1);
 	file->file_seq = file_seq;
-	file->path = str_free_without_data(&str);
+	file->path = i_strdup(str_c(str));
 
 	file->fd = open(file->path, O_CREAT | O_RDWR, 0600);
 	if (file->fd == -1) {
@@ -963,6 +962,18 @@
 			dbox_file_close(file);
 			return -1;
 		}
+
+		if (i < count) {
+			entries[i]->create_time = file->create_time;
+			entries[i]->file_size = file->append_offset;
+		}
+
+		if (!DBOX_CAN_APPEND(mbox, file->create_time,
+				     file->append_offset,
+				     min_usable_timestamp)) {
+			dbox_file_close(file);
+			goto __again;
+		}
 	}
 
 	/* we'll always use CRLF linefeeds for mails (but not the header,
@@ -973,6 +984,9 @@
 
 	o_stream_seek(file->output, file->append_offset);
 
+	save_file = p_new(ctx->pool, struct dbox_save_file, 1);
+	save_file->file = file;
+        save_file->dotlock = dotlock;
 	save_file->dev = st.st_dev;
 	save_file->ino = st.st_ino;
 	ARRAY_CREATE(&save_file->seqs, ctx->pool, unsigned int, 8);