]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Don't sync mbox if it hasn't changed
authorTimo Sirainen <tss@iki.fi>
Sun, 13 Jun 2004 21:50:42 +0000 (00:50 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 13 Jun 2004 21:50:42 +0000 (00:50 +0300)
--HG--
branch : HEAD

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

index 98a2853bb9c2b957f3720a1fbd548a6c65dbeb8e..6745228f72e6e4036ee989fd7304f35afe524ce9 100644 (file)
@@ -207,6 +207,7 @@ static int mbox_sync_do(struct index_mailbox *ibox,
                        struct mail_index_view *sync_view,
                        buffer_t *syncs, struct mail_index_sync_rec *sync_rec)
 {
+       /* a horrible function. needs some serious cleanups. */
        struct mbox_sync_context sync_ctx;
        struct mbox_sync_mail_context mail_ctx;
        struct mail_index_transaction *t;
@@ -583,7 +584,7 @@ static int mbox_sync_do(struct index_mailbox *ibox,
                        offsetof(struct mail_index_header, sync_stamp),
                        &sync_stamp, sizeof(sync_stamp));
        }
-       if ((uint64_t)st.st_mtime != hdr->sync_size) {
+       if ((uint64_t)st.st_size != hdr->sync_size) {
                uint64_t sync_size = st.st_size;
 
                mail_index_update_header(t,
@@ -623,10 +624,29 @@ static int mbox_sync_do(struct index_mailbox *ibox,
        return ret < 0 ? ret : 0;
 }
 
+static int mbox_sync_has_changed(struct index_mailbox *ibox)
+{
+       const struct mail_index_header *hdr;
+       struct stat st;
+
+       if (mail_index_get_header(ibox->view, &hdr) < 0) {
+               mail_storage_set_index_error(ibox);
+               return -1;
+       }
+
+       if (stat(ibox->path, &st) < 0) {
+               mbox_set_syscall_error(ibox, "stat()");
+               return -1;
+       }
+
+       return (uint32_t)st.st_mtime != hdr->sync_stamp ||
+               (uint64_t)st.st_size != hdr->sync_size;
+}
+
 int mbox_sync(struct index_mailbox *ibox, int last_commit)
 {
        struct mail_index_sync_ctx *index_sync_ctx;
-        struct mail_index_view *sync_view;
+       struct mail_index_view *sync_view;
        unsigned int lock_id;
        uint32_t seq;
        uoff_t offset;
@@ -634,6 +654,9 @@ int mbox_sync(struct index_mailbox *ibox, int last_commit)
        buffer_t *syncs;
        int ret, lock_type;
 
+       if ((ret = mbox_sync_has_changed(ibox)) <= 0)
+               return ret;
+
        if (last_commit) {
                seq = ibox->commit_log_file_seq;
                offset = ibox->commit_log_file_offset;
@@ -644,8 +667,11 @@ int mbox_sync(struct index_mailbox *ibox, int last_commit)
 
        ret = mail_index_sync_begin(ibox->index, &index_sync_ctx, &sync_view,
                                    seq, offset);
-       if (ret <= 0)
+       if (ret <= 0) {
+               if (ret < 0)
+                       mail_storage_set_index_error(ibox);
                return ret;
+       }
 
        memset(&sync_rec, 0, sizeof(sync_rec));
        syncs = buffer_create_dynamic(default_pool, 256, (size_t)-1);