changeset 4322:f693898fee3b HEAD

Several dbox fixes backported from branch_1_0
author Timo Sirainen <tss@iki.fi>
date Thu, 08 Jun 2006 20:14:00 +0300
parents 928f9082a322
children af09f5b2ce04
files src/lib-storage/index/dbox/dbox-mail.c src/lib-storage/index/dbox/dbox-sync-full.c src/lib-storage/index/dbox/dbox-uidlist.c
diffstat 3 files changed, 59 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-mail.c	Thu Jun 08 20:07:25 2006 +0300
+++ b/src/lib-storage/index/dbox/dbox-mail.c	Thu Jun 08 20:14:00 2006 +0300
@@ -72,52 +72,69 @@
 	}
 }
 
+static bool dbox_mail_try_open(struct index_mail *mail,
+			       uint32_t *file_seq_r, uoff_t *offset_r,
+			       int *ret_r)
+{
+	struct dbox_mailbox *mbox = (struct dbox_mailbox *)mail->ibox;
+	uint32_t seq = mail->mail.mail.seq;
+
+	*ret_r = dbox_mail_lookup_offset(mail->trans, seq,
+					 file_seq_r, offset_r);
+	if (*ret_r <= 0) {
+		if (*ret_r == 0)
+			mail->mail.mail.expunged = TRUE;
+		return TRUE;
+	}
+
+	if ((*ret_r = dbox_file_seek(mbox, *file_seq_r, *offset_r)) < 0)
+		return TRUE;
+	if (*ret_r > 0) {
+		/* ok */
+		*ret_r = dbox_mail_parse_mail_header(mail, mbox->file);
+		return TRUE;
+	}
+	return FALSE;
+}
+
 static int dbox_mail_open(struct index_mail *mail, uoff_t *offset_r)
 {
 	struct dbox_mailbox *mbox = (struct dbox_mailbox *)mail->ibox;
-	uint32_t seq = mail->mail.mail.seq;
 	uint32_t file_seq, prev_file_seq = 0;
-	uoff_t offset, prev_offset = 0;
+	uoff_t prev_offset = 0;
 	int i, ret;
 
 	if (mail->mail.mail.expunged)
 		return 0;
 
 	for (i = 0; i < 3; i++) {
-		ret = dbox_mail_lookup_offset(mail->trans, seq,
-					      &file_seq, &offset);
-		if (ret <= 0) {
-			if (ret == 0)
-				mail->mail.mail.expunged = TRUE;
+		if (dbox_mail_try_open(mail, &file_seq, offset_r, &ret))
 			return ret;
+
+		if (prev_file_seq == file_seq && prev_offset == *offset_r) {
+			/* broken offset */
+			break;
+		} else {
+			/* mail was moved. resync dbox to find out the new
+			   offset and try again. */
+			if (dbox_sync(mbox, FALSE) < 0)
+				return -1;
 		}
 
-		if ((ret = dbox_file_seek(mbox, file_seq, offset)) < 0)
-			return -1;
-		if (ret > 0) {
-			/* ok */
-			*offset_r = offset;
-			return dbox_mail_parse_mail_header(mail, mbox->file);
-		}
-
-		if (prev_file_seq == file_seq && prev_offset == offset) {
-			/* broken offset */
-			break;
-		}
-
-		/* mail was moved. resync dbox to find out the new offset
-		   and try again. */
-		if (dbox_sync(mbox, FALSE) < 0)
-			return -1;
 		prev_file_seq = file_seq;
-		prev_offset = offset;
+		prev_offset = *offset_r;
 	}
 
 	mail_storage_set_critical(STORAGE(mbox->storage),
 				  "Cached message offset (%u, %"PRIuUOFF_T") "
 				  "broken for uid %u in dbox %s",
-				  file_seq, offset, mail->mail.mail.uid,
+				  file_seq, *offset_r, mail->mail.mail.uid,
 				  mbox->path);
+
+	if (dbox_sync(mbox, TRUE) < 0)
+		return -1;
+	if (dbox_mail_try_open(mail, &file_seq, offset_r, &ret))
+		return ret;
 	return -1;
 }
 
--- a/src/lib-storage/index/dbox/dbox-sync-full.c	Thu Jun 08 20:07:25 2006 +0300
+++ b/src/lib-storage/index/dbox/dbox-sync-full.c	Thu Jun 08 20:14:00 2006 +0300
@@ -186,7 +186,7 @@
 	}
 
 	hdr = mail_index_get_header(ctx->sync_view);
-	while (seq < hdr->messages_count) {
+	while (seq <= hdr->messages_count) {
 		mail_index_expunge(ctx->trans, seq);
 		seq++;
 	}
--- a/src/lib-storage/index/dbox/dbox-uidlist.c	Thu Jun 08 20:07:25 2006 +0300
+++ b/src/lib-storage/index/dbox/dbox-uidlist.c	Thu Jun 08 20:14:00 2006 +0300
@@ -968,7 +968,7 @@
 	/* doesn't exist, make sure that index's last file seq is lower */
 	if (dbox_uidlist_read(mbox->uidlist) < 0)
 		return -1;
-	return file_seq < mbox->uidlist->last_file_seq ? 1 : 0;
+	return file_seq <= mbox->uidlist->last_file_seq ? 1 : 0;
 }
 
 static int
@@ -1016,8 +1016,21 @@
 			   to create the file back and cause problems. */
 			ret = dbox_file_seq_was_used(mbox, str_c(path),
 						     file_seq);
-			if (ret == 0)
+
+			if (i < count) {
+				/* dbox file was re-read, find the entry
+				   again */
+				entries = array_get(&ctx->uidlist->entries,
+						    &count);
+				for (i = 0; i < count; i++) {
+					if (entries[i]->file_seq == file_seq)
+						break;
+				}
+			}
+			if (ret == 0) {
+				i_assert(i < count || !*existing_r);
 				break;
+			}
 
 			/* error / it was used, continue with another
 			   file sequence */