]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Added index_storage_list_index_has_changed_full()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 28 Apr 2016 12:21:41 +0000 (15:21 +0300)
committerGitLab <gitlab@git.dovecot.net>
Thu, 28 Apr 2016 13:21:19 +0000 (16:21 +0300)
This allows the caller to use it to implement a slightly different
mailbox.list_index_has_changed()

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

index 24bf9f2d17e90f797839993022c44976212ff781..be43e1d78c3ea030cb325810380b9d556d4a50c8 100644 (file)
@@ -18,6 +18,16 @@ enum mailbox_lock_notify_type {
        MAILBOX_LOCK_NOTIFY_MAILBOX_OVERRIDE
 };
 
+enum index_storage_list_change {
+       INDEX_STORAGE_LIST_CHANGE_ERROR = -1,
+       INDEX_STORAGE_LIST_CHANGE_NONE = 0,
+       INDEX_STORAGE_LIST_CHANGE_INMEMORY,
+       INDEX_STORAGE_LIST_CHANGE_NORECORD,
+       INDEX_STORAGE_LIST_CHANGE_NOT_IN_FS,
+       INDEX_STORAGE_LIST_CHANGE_SIZE_CHANGED,
+       INDEX_STORAGE_LIST_CHANGE_MTIME_CHANGED
+};
+
 struct index_mailbox_context {
        union mailbox_module_context module_ctx;
        enum mail_index_open_flags index_flags;
@@ -155,6 +165,10 @@ bool index_keyword_array_cmp(const ARRAY_TYPE(keyword_indexes) *k1,
 int index_storage_list_index_has_changed(struct mailbox *box,
                                         struct mail_index_view *list_view,
                                         uint32_t seq);
+enum index_storage_list_change
+index_storage_list_index_has_changed_full(struct mailbox *box,
+                                         struct mail_index_view *list_view,
+                                         uint32_t seq);
 void index_storage_list_index_update_sync(struct mailbox *box,
                                          struct mail_index_transaction *trans,
                                          uint32_t seq);
index 79c44329c289766bcf5b23ebd5e1b4bd46db2a57..0d4aba0ce4d19308566424d3a9e6bf4ed0002ca3 100644 (file)
@@ -403,9 +403,10 @@ index_list_get_ext_id(struct mailbox *box, struct mail_index_view *view)
        return ibox->list_index_sync_ext_id;
 }
 
-int index_storage_list_index_has_changed(struct mailbox *box,
-                                        struct mail_index_view *list_view,
-                                        uint32_t seq)
+enum index_storage_list_change
+index_storage_list_index_has_changed_full(struct mailbox *box,
+                                         struct mail_index_view *list_view,
+                                         uint32_t seq)
 {
        const struct index_storage_list_index_record *rec;
        const void *data;
@@ -416,7 +417,7 @@ int index_storage_list_index_has_changed(struct mailbox *box,
        int ret;
 
        if (mail_index_is_in_memory(mail_index_view_get_index(list_view)))
-               return 1;
+               return INDEX_STORAGE_LIST_CHANGE_INMEMORY;
 
        ext_id = index_list_get_ext_id(box, list_view);
        mail_index_lookup_ext(list_view, seq, ext_id, &data, &expunged);
@@ -424,28 +425,43 @@ int index_storage_list_index_has_changed(struct mailbox *box,
 
        if (rec == NULL || expunged || rec->size == 0 || rec->mtime == 0) {
                /* doesn't exist / not synced */
-               return 1;
+               return INDEX_STORAGE_LIST_CHANGE_NORECORD;
        }
        if (box->storage->set->mailbox_list_index_very_dirty_syncs)
-               return 0;
+               return INDEX_STORAGE_LIST_CHANGE_NONE;
 
        ret = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &dir);
        if (ret < 0)
-               return -1;
+               return INDEX_STORAGE_LIST_CHANGE_ERROR;
        i_assert(ret > 0);
 
        path = t_strconcat(dir, "/", box->index_prefix, ".log", NULL);
        if (stat(path, &st) < 0) {
                if (errno == ENOENT)
-                       return 1;
+                       return INDEX_STORAGE_LIST_CHANGE_NOT_IN_FS;
                mail_storage_set_critical(box->storage,
                                          "stat(%s) failed: %m", path);
-               return -1;
+               return INDEX_STORAGE_LIST_CHANGE_ERROR;
        }
-       if (rec->size != (st.st_size & 0xffffffffU) ||
-           rec->mtime != (st.st_mtime & 0xffffffffU))
+       if (rec->size != (st.st_size & 0xffffffffU))
+               return INDEX_STORAGE_LIST_CHANGE_SIZE_CHANGED;
+       if (rec->mtime != (st.st_mtime & 0xffffffffU))
+               return INDEX_STORAGE_LIST_CHANGE_MTIME_CHANGED;
+       return INDEX_STORAGE_LIST_CHANGE_NONE;
+}
+
+int index_storage_list_index_has_changed(struct mailbox *box,
+                                        struct mail_index_view *list_view,
+                                        uint32_t seq)
+{
+       switch (index_storage_list_index_has_changed_full(box, list_view, seq)) {
+       case INDEX_STORAGE_LIST_CHANGE_ERROR:
+               return -1;
+       case INDEX_STORAGE_LIST_CHANGE_NONE:
+               return 0;
+       default:
                return 1;
-       return 0;
+       }
 }
 
 void index_storage_list_index_update_sync(struct mailbox *box,