[dovecot-cvs] dovecot/src/lib-storage/index/mbox istream-raw-mbox.c, 1.10, 1.11 istream-raw-mbox.h, 1.5, 1.6 mbox-sync-private.h, 1.14, 1.15 mbox-sync.c, 1.32, 1.33

cras at procontrol.fi cras at procontrol.fi
Fri Jun 18 03:33:10 EEST 2004


Update of /home/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv27460/lib-storage/index/mbox

Modified Files:
	istream-raw-mbox.c istream-raw-mbox.h mbox-sync-private.h 
	mbox-sync.c 
Log Message:
Added istream_raw_mbox_is_eof() and fixed updating UIDVALIDITY in index



Index: istream-raw-mbox.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/istream-raw-mbox.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- istream-raw-mbox.c	17 Jun 2004 23:08:48 -0000	1.10
+++ istream-raw-mbox.c	18 Jun 2004 00:33:08 -0000	1.11
@@ -18,7 +18,7 @@
 
 	unsigned int corrupted:1;
 	unsigned int eom:1;
-	unsigned int next_eof:1;
+	unsigned int eof:1;
 };
 
 static void _close(struct _iostream *stream __attr_unused__)
@@ -139,7 +139,6 @@
 				stream->istream.v_offset +
 				(stream->pos - stream->skip);
 		}
-		stream->istream.eof = rstream->next_eof;
 		return -1;
 	}
 
@@ -173,7 +172,7 @@
 		stream->pos = pos;
 
 		rstream->eom = TRUE;
-		rstream->next_eof = TRUE;
+		rstream->eof = TRUE;
 		handle_end_of_mail(rstream, pos);
 		return ret < 0 ? _read(stream) : ret;
 	}
@@ -182,7 +181,7 @@
 		/* beginning of message, we haven't yet read our From-line */
 		if (mbox_read_from_line(rstream) < 0) {
 			stream->pos = 0;
-			stream->istream.eof = TRUE;
+			rstream->eof = TRUE;
 			rstream->corrupted = TRUE;
 			return -1;
 		}
@@ -270,7 +269,7 @@
 
         rstream->input_peak_offset = 0;
 	rstream->eom = FALSE;
-	rstream->next_eof = FALSE;
+	rstream->eof = FALSE;
 }
 
 struct istream *i_stream_create_raw_mbox(pool_t pool, struct istream *input)
@@ -447,14 +446,13 @@
 	rstream->hdr_offset = rstream->from_offset;
 	rstream->body_offset = (uoff_t)-1;
 
-	/* don't clear stream->eof if we don't have to */
 	if (stream->v_offset != rstream->from_offset)
 		i_stream_seek(stream, rstream->from_offset);
 	i_stream_seek(rstream->input, rstream->from_offset);
 
         rstream->input_peak_offset = 0;
 	rstream->eom = FALSE;
-	rstream->next_eof = FALSE;
+	rstream->eof = FALSE;
 }
 
 int istream_raw_mbox_seek(struct istream *stream, uoff_t offset)
@@ -465,7 +463,7 @@
 
 	rstream->corrupted = FALSE;
 	rstream->eom = FALSE;
-	rstream->next_eof = FALSE;
+	rstream->eof = FALSE;
         rstream->input_peak_offset = 0;
 
 	if (rstream->mail_size != (uoff_t)-1 &&
@@ -514,3 +512,11 @@
 	rstream->istream.skip = 0;
 	rstream->istream.pos = 0;
 }
+
+int istream_raw_mbox_is_eof(struct istream *stream)
+{
+	struct raw_mbox_istream *rstream =
+		(struct raw_mbox_istream *)stream->real_stream;
+
+	return rstream->eof;
+}

Index: istream-raw-mbox.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/istream-raw-mbox.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- istream-raw-mbox.h	16 Jun 2004 05:38:23 -0000	1.5
+++ istream-raw-mbox.h	18 Jun 2004 00:33:08 -0000	1.6
@@ -36,4 +36,7 @@
 /* Flush all buffering. Call if you modify the mbox. */
 void istream_raw_mbox_flush(struct istream *stream);
 
+/* Returns TRUE if we've read the whole mbox. */
+int istream_raw_mbox_is_eof(struct istream *stream);
+
 #endif

Index: mbox-sync-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- mbox-sync-private.h	17 Jun 2004 23:08:48 -0000	1.14
+++ mbox-sync-private.h	18 Jun 2004 00:33:08 -0000	1.15
@@ -94,6 +94,7 @@
 	off_t expunged_space, space_diff;
 
 	unsigned int dest_first_mail:1;
+	unsigned int seen_first_mail:1;
 };
 
 int mbox_sync(struct index_mailbox *ibox, int last_commit, int lock);

Index: mbox-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- mbox-sync.c	18 Jun 2004 00:06:34 -0000	1.32
+++ mbox-sync.c	18 Jun 2004 00:33:08 -0000	1.33
@@ -185,9 +185,9 @@
 mbox_sync_read_next_mail(struct mbox_sync_context *sync_ctx,
 			 struct mbox_sync_mail_context *mail_ctx)
 {
-	/* set input->eof */
+	/* get EOF */
 	(void)istream_raw_mbox_get_header_offset(sync_ctx->input);
-	if (sync_ctx->input->eof)
+	if (istream_raw_mbox_is_eof(sync_ctx->input))
 		return 0;
 
 	memset(mail_ctx, 0, sizeof(*mail_ctx));
@@ -200,6 +200,8 @@
 	mail_ctx->mail.offset =
 		istream_raw_mbox_get_header_offset(sync_ctx->input);
 
+	if (mail_ctx->seq == 1)
+		sync_ctx->seen_first_mail = TRUE;
 	if (mail_ctx->seq > 1 && sync_ctx->dest_first_mail) {
 		/* First message was expunged and this is the next one.
 		   Skip \n header */
@@ -758,7 +760,7 @@
 		}
 	}
 
-	if (sync_ctx->input->eof) {
+	if (istream_raw_mbox_is_eof(sync_ctx->input)) {
 		/* rest of the messages in index don't exist -> expunge them */
 		messages_count =
 			mail_index_view_get_message_count(sync_ctx->sync_view);
@@ -774,7 +776,7 @@
 {
 	uoff_t offset, extra_space, trailer_size;
 
-	if (!sync_ctx->input->eof) {
+	if (!istream_raw_mbox_is_eof(sync_ctx->input)) {
 		i_assert(sync_ctx->need_space_seq == 0);
 		i_assert(sync_ctx->expunged_space == 0);
 		return 0;
@@ -860,8 +862,8 @@
 
 	if ((sync_ctx->base_uid_validity != 0 &&
 	     sync_ctx->base_uid_validity != sync_ctx->hdr->uid_validity) ||
-	    sync_ctx->hdr->uid_validity == 0) {
-		if (sync_ctx->hdr->uid_validity == 0) {
+	    (sync_ctx->hdr->uid_validity == 0 && sync_ctx->seen_first_mail)) {
+		if (sync_ctx->base_uid_validity == 0) {
 			/* we couldn't rewrite X-IMAPbase because it's
 			   a read-only mbox */
 			i_assert(sync_ctx->ibox->mbox_readonly);
@@ -872,7 +874,8 @@
 			&sync_ctx->base_uid_validity,
 			sizeof(sync_ctx->base_uid_validity));
 	}
-	if (sync_ctx->input->eof &&
+
+	if (istream_raw_mbox_is_eof(sync_ctx->input) &&
 	    sync_ctx->next_uid != sync_ctx->hdr->next_uid) {
 		i_assert(sync_ctx->next_uid != 0);
 		mail_index_update_header(sync_ctx->t,
@@ -907,7 +910,8 @@
 	sync_ctx->prev_msg_uid = 0;
 	sync_ctx->seq = sync_ctx->idx_seq = 0;
 
-        sync_ctx->dest_first_mail = TRUE;
+	sync_ctx->dest_first_mail = TRUE;
+        sync_ctx->seen_first_mail = FALSE;
 }
 
 static int mbox_sync_do(struct mbox_sync_context *sync_ctx)



More information about the dovecot-cvs mailing list