]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fixes
authorTimo Sirainen <tss@iki.fi>
Wed, 29 Oct 2003 15:45:41 +0000 (17:45 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 29 Oct 2003 15:45:41 +0000 (17:45 +0200)
--HG--
branch : HEAD

src/lib-index/mbox/mbox-sync-full.c
src/lib-index/mbox/mbox-sync.c

index a3ada1ea27e61ce3a7fc06046f85e8d3361d6798..1d447c677cfd2c78eab10c6a85da60a56e2b4948 100644 (file)
@@ -84,7 +84,7 @@ static int match_next_record(struct mail_index *index,
        uoff_t hdr_size, body_size;
        unsigned char current_digest[16];
        unsigned int first_seq, last_seq;
-       int hdr_size_fixed;
+       int ret, hdr_size_fixed;
 
        *next_rec = NULL;
 
@@ -94,10 +94,10 @@ static int match_next_record(struct mail_index *index,
 
        first_rec = last_rec = NULL;
        first_seq = last_seq = 0;
-       hdr_size = 0; body_offset = 0; hdr_size_fixed = FALSE;
+       ret = 0; hdr_size = 0; body_offset = 0; hdr_size_fixed = FALSE;
        do {
                if (!mbox_mail_get_location(index, rec, &offset, &body_size))
-                       return FALSE;
+                       return -1;
 
                i_stream_seek(input, header_offset);
 
@@ -123,7 +123,7 @@ static int match_next_record(struct mail_index *index,
                                if (!mbox_check_uidvalidity(index,
                                                            ctx.uid_validity)) {
                                        /* uidvalidity changed, abort */
-                                       return FALSE;
+                                       return -1;
                                }
 
                                if (ctx.uid_last >= index->header->next_uid) {
@@ -149,7 +149,7 @@ static int match_next_record(struct mail_index *index,
                                if (!index->update_flags(index, rec, *seq,
                                                         MODIFY_REPLACE,
                                                         ctx.flags, TRUE))
-                                       return FALSE;
+                                       return -1;
                        } else if (rec->msg_flags == ctx.flags) {
                                /* flags are same, it's not dirty anymore */
                                index_flags &= ~MAIL_INDEX_FLAG_DIRTY;
@@ -163,8 +163,9 @@ static int match_next_record(struct mail_index *index,
                        if (offset != header_offset) {
                                if (!mail_cache_update_location_offset(
                                        index->cache, rec, header_offset))
-                                       return FALSE;
+                                       return -1;
                        }
+                       ret = 1;
                        break;
                }
 
@@ -185,13 +186,13 @@ static int match_next_record(struct mail_index *index,
        } else {
                if (!index->expunge(index, first_rec, last_rec,
                                    first_seq, last_seq, TRUE))
-                       return FALSE;
+                       return -1;
 
                *seq = first_seq + 1;
                *next_rec = index->lookup(index, *seq);
        }
 
-       return TRUE;
+       return ret;
 }
 
 static int mbox_sync_from_stream(struct mail_index *index,
@@ -202,7 +203,7 @@ static int mbox_sync_from_stream(struct mail_index *index,
        const unsigned char *data;
        size_t size;
        unsigned int seq;
-       int dirty;
+       int dirty, ret;
 
        if (mail_cache_lock(index->cache, FALSE) <= 0)
                return FALSE;
@@ -250,10 +251,11 @@ static int mbox_sync_from_stream(struct mail_index *index,
                if (input->v_offset == input->v_size)
                        break;
 
-               if (!match_next_record(index, rec, &seq, input, &rec, &dirty))
+               ret = match_next_record(index, rec, &seq, input, &rec, &dirty);
+               if (ret < 0)
                        return FALSE;
 
-               if (rec == NULL) {
+               if (ret == 0) {
                        /* Get back to line before From */
                        i_stream_seek(input, from_offset);
                }
index ea5ebdb83c2ea4ba6cf4206f330cf0539720dda1..2b9362d0c1dd756030c083a7f4584d1d416d752b 100644 (file)
@@ -38,7 +38,6 @@ int mbox_index_sync(struct mail_index *index, int minimal_sync __attr_unused__,
                    enum mail_lock_type data_lock_type, int *changes)
 {
        struct stat st;
-       uoff_t filesize;
        int count, fd;
 
        if (index->mailbox_readonly && data_lock_type == MAIL_LOCK_EXCLUSIVE) {
@@ -72,7 +71,6 @@ int mbox_index_sync(struct mail_index *index, int minimal_sync __attr_unused__,
                else if (errno != EEXIST)
                        return mbox_set_syscall_error(index, "open()");
        }
-       filesize = st.st_size;
 
        if (index->mbox_fd != -1 &&
            (index->mbox_ino != st.st_ino ||
@@ -86,7 +84,8 @@ int mbox_index_sync(struct mail_index *index, int minimal_sync __attr_unused__,
                 mbox_file_close_fd(index);
        }
 
-       if (index->sync_stamp != st.st_mtime || index->sync_size != filesize) {
+       if (index->sync_stamp != st.st_mtime ||
+           index->sync_size != (uoff_t)st.st_size) {
                mbox_file_close_stream(index);
 
                if (changes != NULL)
@@ -101,8 +100,11 @@ int mbox_index_sync(struct mail_index *index, int minimal_sync __attr_unused__,
                                return FALSE;
                }
 
+               if (fstat(index->mbox_fd, &st) < 0)
+                       return mbox_set_syscall_error(index, "fstat()");
+
                index->sync_stamp = st.st_mtime;
-               index->sync_size = filesize;
+               index->sync_size = st.st_size;
        }
 
        /* we need some index lock to be able to lock mbox */