From: Timo Sirainen Date: Wed, 19 Aug 2015 12:12:09 +0000 (+0300) Subject: lib-storage: Moved index/index-mailbox-check.c code to mailbox-watch.c X-Git-Tag: 2.2.19.rc1~213 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7e2671b295927b461adc8b6c4ed6a1c4761fb323;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Moved index/index-mailbox-check.c code to mailbox-watch.c This changes the API, but adds backwards compatibility macros. --- diff --git a/src/lib-storage/Makefile.am b/src/lib-storage/Makefile.am index 81182b58bb..822a053808 100644 --- a/src/lib-storage/Makefile.am +++ b/src/lib-storage/Makefile.am @@ -54,7 +54,8 @@ libstorage_la_SOURCES = \ mailbox-recent-flags.c \ mailbox-search-result.c \ mailbox-tree.c \ - mailbox-uidvalidity.c + mailbox-uidvalidity.c \ + mailbox-watch.c headers = \ fail-mail-storage.h \ @@ -83,7 +84,8 @@ headers = \ mailbox-recent-flags.h \ mailbox-search-result-private.h \ mailbox-tree.h \ - mailbox-uidvalidity.h + mailbox-uidvalidity.h \ + mailbox-watch.h shlibs = \ @LINKED_STORAGE_LIBS@ \ diff --git a/src/lib-storage/index/Makefile.am b/src/lib-storage/index/Makefile.am index 92597653b4..742b1f4da1 100644 --- a/src/lib-storage/index/Makefile.am +++ b/src/lib-storage/index/Makefile.am @@ -19,7 +19,6 @@ libstorage_index_la_SOURCES = \ index-mail.c \ index-mail-binary.c \ index-mail-headers.c \ - index-mailbox-check.c \ index-mailbox-size.c \ index-rebuild.c \ index-search.c \ diff --git a/src/lib-storage/index/cydir/cydir-storage.c b/src/lib-storage/index/cydir/cydir-storage.c index ed39366d63..329af53403 100644 --- a/src/lib-storage/index/cydir/cydir-storage.c +++ b/src/lib-storage/index/cydir/cydir-storage.c @@ -103,9 +103,9 @@ cydir_mailbox_create(struct mailbox *box, const struct mailbox_update *update, static void cydir_notify_changes(struct mailbox *box) { if (box->notify_callback == NULL) - index_mailbox_check_remove_all(box); + mailbox_watch_remove_all(box); else - index_mailbox_check_add(box, mailbox_get_path(box)); + mailbox_watch_add(box, mailbox_get_path(box)); } struct mail_storage cydir_storage = { diff --git a/src/lib-storage/index/dbox-common/dbox-storage.c b/src/lib-storage/index/dbox-common/dbox-storage.c index 003659a035..92b5cfe5ec 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.c +++ b/src/lib-storage/index/dbox-common/dbox-storage.c @@ -155,13 +155,13 @@ void dbox_notify_changes(struct mailbox *box) const char *dir, *path; if (box->notify_callback == NULL) - index_mailbox_check_remove_all(box); + mailbox_watch_remove_all(box); else { if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &dir) <= 0) return; path = t_strdup_printf("%s/"MAIL_INDEX_PREFIX".log", dir); - index_mailbox_check_add(box, path); + mailbox_watch_add(box, path); } } diff --git a/src/lib-storage/index/index-storage.c b/src/lib-storage/index/index-storage.c index d0585d176c..df4ca02272 100644 --- a/src/lib-storage/index/index-storage.c +++ b/src/lib-storage/index/index-storage.c @@ -354,7 +354,7 @@ void index_storage_mailbox_close(struct mailbox *box) { struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); - index_mailbox_check_remove_all(box); + mailbox_watch_remove_all(box); if (box->input != NULL) i_stream_unref(&box->input); diff --git a/src/lib-storage/index/index-storage.h b/src/lib-storage/index/index-storage.h index 8de8576c40..08ff0877ad 100644 --- a/src/lib-storage/index/index-storage.h +++ b/src/lib-storage/index/index-storage.h @@ -5,6 +5,7 @@ #include "mail-storage-private.h" #include "mail-index-private.h" #include "mailbox-recent-flags.h" /* FIXME: remove in v2.3 */ +#include "mailbox-watch.h" #define MAILBOX_FULL_SYNC_INTERVAL 5 @@ -21,9 +22,6 @@ struct index_mailbox_context { union mailbox_module_context module_ctx; enum mail_index_open_flags index_flags; - struct timeout *notify_to, *notify_delay_to; - struct index_notify_file *notify_files; - time_t next_lock_notify; /* temporary */ enum mailbox_lock_notify_type last_notify_type; @@ -77,9 +75,8 @@ bool index_storage_is_inconsistent(struct mailbox *box); /* FIXME: for backwards compatibility - remove in v2.3 */ #define index_mailbox_set_recent_seq(box, view, seq1, seq2) \ mailbox_recent_flags_set_seqs(box, view, seq1, seq2) - -void index_mailbox_check_add(struct mailbox *box, const char *path); -void index_mailbox_check_remove_all(struct mailbox *box); +#define index_mailbox_check_add(box, path) mailbox_watch_add(box, path) +#define index_mailbox_check_remove_all(box) mailbox_watch_remove_all(box) enum mail_index_sync_flags index_storage_get_sync_flags(struct mailbox *box); bool index_mailbox_want_full_sync(struct mailbox *box, diff --git a/src/lib-storage/index/index-sync.c b/src/lib-storage/index/index-sync.c index 3b569ba3ff..21baa3fc95 100644 --- a/src/lib-storage/index/index-sync.c +++ b/src/lib-storage/index/index-sync.c @@ -45,8 +45,8 @@ bool index_mailbox_want_full_sync(struct mailbox *box, return FALSE; } - if (ibox->notify_to != NULL) - timeout_reset(ibox->notify_to); + if (box->to_notify != NULL) + timeout_reset(box->to_notify); ibox->sync_last_check = ioloop_time; return TRUE; } diff --git a/src/lib-storage/index/maildir/maildir-storage.c b/src/lib-storage/index/maildir/maildir-storage.c index 7fbd565a21..9685252e92 100644 --- a/src/lib-storage/index/maildir/maildir-storage.c +++ b/src/lib-storage/index/maildir/maildir-storage.c @@ -579,11 +579,11 @@ static void maildir_notify_changes(struct mailbox *box) const char *box_path = mailbox_get_path(box); if (box->notify_callback == NULL) - index_mailbox_check_remove_all(&mbox->box); + mailbox_watch_remove_all(&mbox->box); else { - index_mailbox_check_add(&mbox->box, + mailbox_watch_add(&mbox->box, t_strconcat(box_path, "/new", NULL)); - index_mailbox_check_add(&mbox->box, + mailbox_watch_add(&mbox->box, t_strconcat(box_path, "/cur", NULL)); } } diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index e4ebc5f8d3..561fe9b495 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -680,9 +680,9 @@ static void mbox_notify_changes(struct mailbox *box) struct mbox_mailbox *mbox = (struct mbox_mailbox *)box; if (box->notify_callback == NULL) - index_mailbox_check_remove_all(box); + mailbox_watch_remove_all(box); else if (!mbox->no_mbox_file) - index_mailbox_check_add(box, mailbox_get_path(box)); + mailbox_watch_add(box, mailbox_get_path(box)); } static bool diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 00ba4858c4..03d7f27af5 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -329,6 +329,8 @@ struct mailbox { /* Mailbox notification settings: */ mailbox_notify_callback_t *notify_callback; void *notify_context; + struct timeout *to_notify, *to_notify_delay; + struct mailbox_notify_file *notify_files; /* Increased by one for each new struct mailbox. */ unsigned int generation_sequence; diff --git a/src/lib-storage/index/index-mailbox-check.c b/src/lib-storage/mailbox-watch.c similarity index 51% rename from src/lib-storage/index/index-mailbox-check.c rename to src/lib-storage/mailbox-watch.c index 495f0f3d6d..8b5dc220d1 100644 --- a/src/lib-storage/index/index-mailbox-check.c +++ b/src/lib-storage/mailbox-watch.c @@ -2,7 +2,8 @@ #include "lib.h" #include "ioloop.h" -#include "index-storage.h" +#include "mail-storage-private.h" +#include "mailbox-watch.h" #include #include @@ -11,8 +12,8 @@ #define NOTIFY_DELAY_MSECS 500 -struct index_notify_file { - struct index_notify_file *next; +struct mailbox_notify_file { + struct mailbox_notify_file *next; char *path; time_t last_stamp; @@ -21,21 +22,18 @@ struct index_notify_file { static void notify_delay_callback(struct mailbox *box) { - struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); - - if (ibox->notify_delay_to != NULL) - timeout_remove(&ibox->notify_delay_to); + if (box->to_notify_delay != NULL) + timeout_remove(&box->to_notify_delay); box->notify_callback(box, box->notify_context); } -static void check_timeout(struct mailbox *box) +static void notify_timeout(struct mailbox *box) { - struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); - struct index_notify_file *file; + struct mailbox_notify_file *file; struct stat st; bool notify = FALSE; - for (file = ibox->notify_files; file != NULL; file = file->next) { + for (file = box->notify_files; file != NULL; file = file->next) { if (stat(file->path, &st) == 0 && file->last_stamp != st.st_mtime) { file->last_stamp = st.st_mtime; @@ -49,22 +47,19 @@ static void check_timeout(struct mailbox *box) static void notify_callback(struct mailbox *box) { - struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); - - timeout_reset(ibox->notify_to); + timeout_reset(box->to_notify); - if (ibox->notify_delay_to == NULL) { - ibox->notify_delay_to = + if (box->to_notify_delay == NULL) { + box->to_notify_delay = timeout_add_short(NOTIFY_DELAY_MSECS, notify_delay_callback, box); } } -void index_mailbox_check_add(struct mailbox *box, const char *path) +void mailbox_watch_add(struct mailbox *box, const char *path) { - struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); const struct mail_storage_settings *set = box->storage->set; - struct index_notify_file *file; + struct mailbox_notify_file *file; struct stat st; struct io *io = NULL; @@ -72,32 +67,31 @@ void index_mailbox_check_add(struct mailbox *box, const char *path) (void)io_add_notify(path, notify_callback, box, &io); - file = i_new(struct index_notify_file, 1); + file = i_new(struct mailbox_notify_file, 1); file->path = i_strdup(path); file->last_stamp = stat(path, &st) < 0 ? 0 : st.st_mtime; file->io_notify = io; - file->next = ibox->notify_files; - ibox->notify_files = file; + file->next = box->notify_files; + box->notify_files = file; /* we still add a timeout if we don't have one already, * because we don't know what happens with [di]notify * when the filesystem is remote (NFS, ...) */ - if (ibox->notify_to == NULL) { - ibox->notify_to = + if (box->to_notify == NULL) { + box->to_notify = timeout_add(set->mailbox_idle_check_interval * 1000, - check_timeout, box); + notify_timeout, box); } } -void index_mailbox_check_remove_all(struct mailbox *box) +void mailbox_watch_remove_all(struct mailbox *box) { - struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); - struct index_notify_file *file; + struct mailbox_notify_file *file; - while (ibox->notify_files != NULL) { - file = ibox->notify_files; - ibox->notify_files = file->next; + while (box->notify_files != NULL) { + file = box->notify_files; + box->notify_files = file->next; if (file->io_notify != NULL) io_remove(&file->io_notify); @@ -105,8 +99,8 @@ void index_mailbox_check_remove_all(struct mailbox *box) i_free(file); } - if (ibox->notify_delay_to != NULL) - timeout_remove(&ibox->notify_delay_to); - if (ibox->notify_to != NULL) - timeout_remove(&ibox->notify_to); + if (box->to_notify_delay != NULL) + timeout_remove(&box->to_notify_delay); + if (box->to_notify != NULL) + timeout_remove(&box->to_notify); } diff --git a/src/lib-storage/mailbox-watch.h b/src/lib-storage/mailbox-watch.h new file mode 100644 index 0000000000..49317357d3 --- /dev/null +++ b/src/lib-storage/mailbox-watch.h @@ -0,0 +1,7 @@ +#ifndef MAILBOX_WATCH_H +#define MAILBOX_WATCH_H + +void mailbox_watch_add(struct mailbox *box, const char *path); +void mailbox_watch_remove_all(struct mailbox *box); + +#endif