]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added istream_raw_mbox_is_eof() and fixed updating UIDVALIDITY in index
authorTimo Sirainen <tss@iki.fi>
Fri, 18 Jun 2004 00:33:08 +0000 (03:33 +0300)
committerTimo Sirainen <tss@iki.fi>
Fri, 18 Jun 2004 00:33:08 +0000 (03:33 +0300)
--HG--
branch : HEAD

src/lib-storage/index/mbox/istream-raw-mbox.c
src/lib-storage/index/mbox/istream-raw-mbox.h
src/lib-storage/index/mbox/mbox-sync-private.h
src/lib-storage/index/mbox/mbox-sync.c

index 5cb9a57198ef41a49d37e951505845623d3c4614..906077c8dd31e3419e58534517fb4de5af5b2e68 100644 (file)
@@ -18,7 +18,7 @@ struct raw_mbox_istream {
 
        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 @@ static ssize_t _read(struct _istream *stream)
                                stream->istream.v_offset +
                                (stream->pos - stream->skip);
                }
-               stream->istream.eof = rstream->next_eof;
                return -1;
        }
 
@@ -173,7 +172,7 @@ static ssize_t _read(struct _istream *stream)
                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 @@ static ssize_t _read(struct _istream *stream)
                /* 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 @@ static void _seek(struct _istream *stream, uoff_t v_offset)
 
         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 @@ void istream_raw_mbox_next(struct istream *stream, uoff_t body_size)
        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 @@ int istream_raw_mbox_seek(struct istream *stream, uoff_t offset)
 
        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 @@ void istream_raw_mbox_flush(struct istream *stream)
        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 e428d6bb801d65f7f9a005c6f50eeaf82a896cb7..ad647cae33447e73a35dec44a965bd6ecc06bf0a 100644 (file)
@@ -36,4 +36,7 @@ int istream_raw_mbox_seek(struct istream *stream, uoff_t offset);
 /* 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 c852e690e41d4c01b1f37e84a301cc59565ce1b2..d93db049dddb2b080923e19ef4478e39c2c6d2e0 100644 (file)
@@ -94,6 +94,7 @@ struct mbox_sync_context {
        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 b48453f555d4dbdf89dae8c4b8c9c9d3c3deaf62..47f939f9256230f0329d365c3ceff246b35e9365 100644 (file)
@@ -185,9 +185,9 @@ static int
 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 @@ mbox_sync_read_next_mail(struct mbox_sync_context *sync_ctx,
        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 @@ static int mbox_sync_loop(struct mbox_sync_context *sync_ctx,
                }
        }
 
-       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 @@ static int mbox_sync_handle_eof_updates(struct mbox_sync_context *sync_ctx,
 {
        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 @@ static int mbox_sync_update_index_header(struct mbox_sync_context *sync_ctx)
 
        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 @@ static int mbox_sync_update_index_header(struct mbox_sync_context *sync_ctx)
                        &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 @@ static void mbox_sync_restart(struct mbox_sync_context *sync_ctx)
        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)