]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Moved index/index-mailbox-check.c code to mailbox-watch.c
authorTimo Sirainen <tss@iki.fi>
Wed, 19 Aug 2015 12:12:09 +0000 (15:12 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 19 Aug 2015 12:12:09 +0000 (15:12 +0300)
This changes the API, but adds backwards compatibility macros.

12 files changed:
src/lib-storage/Makefile.am
src/lib-storage/index/Makefile.am
src/lib-storage/index/cydir/cydir-storage.c
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/index-storage.c
src/lib-storage/index/index-storage.h
src/lib-storage/index/index-sync.c
src/lib-storage/index/maildir/maildir-storage.c
src/lib-storage/index/mbox/mbox-storage.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mailbox-watch.c [moved from src/lib-storage/index/index-mailbox-check.c with 51% similarity]
src/lib-storage/mailbox-watch.h [new file with mode: 0644]

index 81182b58bb50fd1410b798071fa5b34ccde5f752..822a053808b2a912f92425fb92fda64498f4d152 100644 (file)
@@ -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@ \
index 92597653b4004d6f000902075d8032e09a3b5c89..742b1f4da1d565be21bc055c8a5e992039f68ac6 100644 (file)
@@ -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 \
index ed39366d63c6ffd0c1bb27f0109dd75507882205..329af534033768da46409d1088bf2e8b2e51ece3 100644 (file)
@@ -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 = {
index 003659a0358cbf1778f4894839a6f8870e78c5fa..92b5cfe5ec1b22f0adb42694cd89af875d8b4ec2 100644 (file)
@@ -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);
        }
 }
 
index d0585d176c5a4f8fb6f9efc03ef4cbca536b901c..df4ca0227214f1711e0784fc996064e77791778f 100644 (file)
@@ -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);
 
index 8de8576c402bbd1f9b145a22e89eb9374a6b448c..08ff0877ad78ff590f10ffd8d5f307c2f1c14f1b 100644 (file)
@@ -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,
index 3b569ba3ffdf116fdd2be14a4e82ec584c97da23..21baa3fc953f8e801655979bba3279b8be74902e 100644 (file)
@@ -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;
 }
index 7fbd565a213be2858b7f37e6c94f4682021504ac..9685252e922e7a329ece596c32cd1aae335ba9cd 100644 (file)
@@ -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));
        }
 }
index e4ebc5f8d31f525c70a53176de06d9239fd03505..561fe9b49571f46e2f670bbe640fd8fdaaafb520 100644 (file)
@@ -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
index 00ba4858c45edc73c3fc43106433b6f1da169c4f..03d7f27af5a69dc15a45314615c7d6eb53b8b8a3 100644 (file)
@@ -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;
similarity index 51%
rename from src/lib-storage/index/index-mailbox-check.c
rename to src/lib-storage/mailbox-watch.c
index 495f0f3d6d00a1969f2253aac379a097db85eebf..8b5dc220d100470729062bb243f00e30bfff0fca 100644 (file)
@@ -2,7 +2,8 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "index-storage.h"
+#include "mail-storage-private.h"
+#include "mailbox-watch.h"
 
 #include <stdlib.h>
 #include <unistd.h>
@@ -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 (file)
index 0000000..4931735
--- /dev/null
@@ -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