From: Timo Sirainen Date: Thu, 28 Apr 2016 12:21:41 +0000 (+0300) Subject: lib-storage: Added index_storage_list_index_has_changed_full() X-Git-Tag: 2.3.0.rc1~3920 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b1f4c104714567a42a53040eae8c99e7c7ed9dc;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Added index_storage_list_index_has_changed_full() This allows the caller to use it to implement a slightly different mailbox.list_index_has_changed() --- diff --git a/src/lib-storage/index/index-storage.h b/src/lib-storage/index/index-storage.h index 24bf9f2d17..be43e1d78c 100644 --- a/src/lib-storage/index/index-storage.h +++ b/src/lib-storage/index/index-storage.h @@ -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); diff --git a/src/lib-storage/index/index-sync.c b/src/lib-storage/index/index-sync.c index 79c44329c2..0d4aba0ce4 100644 --- a/src/lib-storage/index/index-sync.c +++ b/src/lib-storage/index/index-sync.c @@ -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,