dovecot-2.2: lib-storage: Moved index/index-mailbox-check.c code...

dovecot at dovecot.org dovecot at dovecot.org
Wed Aug 19 13:51:03 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/f84c81ed5d09
changeset: 18981:f84c81ed5d09
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Aug 19 15:12:09 2015 +0300
description:
lib-storage: Moved index/index-mailbox-check.c code to mailbox-watch.c
This changes the API, but adds backwards compatibility macros.

diffstat:

 src/lib-storage/Makefile.am                      |    6 +-
 src/lib-storage/index/Makefile.am                |    1 -
 src/lib-storage/index/cydir/cydir-storage.c      |    4 +-
 src/lib-storage/index/dbox-common/dbox-storage.c |    4 +-
 src/lib-storage/index/index-mailbox-check.c      |  112 -----------------------
 src/lib-storage/index/index-storage.c            |    2 +-
 src/lib-storage/index/index-storage.h            |    9 +-
 src/lib-storage/index/index-sync.c               |    4 +-
 src/lib-storage/index/maildir/maildir-storage.c  |    6 +-
 src/lib-storage/index/mbox/mbox-storage.c        |    4 +-
 src/lib-storage/mail-storage-private.h           |    2 +
 src/lib-storage/mailbox-watch.c                  |  106 +++++++++++++++++++++
 src/lib-storage/mailbox-watch.h                  |    7 +
 13 files changed, 134 insertions(+), 133 deletions(-)

diffs (truncated from 409 to 300 lines):

diff -r 39255150d521 -r f84c81ed5d09 src/lib-storage/Makefile.am
--- a/src/lib-storage/Makefile.am	Wed Aug 19 14:47:51 2015 +0300
+++ b/src/lib-storage/Makefile.am	Wed Aug 19 15:12:09 2015 +0300
@@ -54,7 +54,8 @@
 	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 @@
 	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 -r 39255150d521 -r f84c81ed5d09 src/lib-storage/index/Makefile.am
--- a/src/lib-storage/index/Makefile.am	Wed Aug 19 14:47:51 2015 +0300
+++ b/src/lib-storage/index/Makefile.am	Wed Aug 19 15:12:09 2015 +0300
@@ -19,7 +19,6 @@
 	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 -r 39255150d521 -r f84c81ed5d09 src/lib-storage/index/cydir/cydir-storage.c
--- a/src/lib-storage/index/cydir/cydir-storage.c	Wed Aug 19 14:47:51 2015 +0300
+++ b/src/lib-storage/index/cydir/cydir-storage.c	Wed Aug 19 15:12:09 2015 +0300
@@ -103,9 +103,9 @@
 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 -r 39255150d521 -r f84c81ed5d09 src/lib-storage/index/dbox-common/dbox-storage.c
--- a/src/lib-storage/index/dbox-common/dbox-storage.c	Wed Aug 19 14:47:51 2015 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-storage.c	Wed Aug 19 15:12:09 2015 +0300
@@ -155,13 +155,13 @@
 	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 -r 39255150d521 -r f84c81ed5d09 src/lib-storage/index/index-mailbox-check.c
--- a/src/lib-storage/index/index-mailbox-check.c	Wed Aug 19 14:47:51 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-/* Copyright (c) 2002-2015 Dovecot authors, see the included COPYING file */
-
-#include "lib.h"
-#include "ioloop.h"
-#include "index-storage.h"
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-
-#define NOTIFY_DELAY_MSECS 500
-
-struct index_notify_file {
-	struct index_notify_file *next;
-
-	char *path;
-	time_t last_stamp;
-	struct io *io_notify;
-};
-
-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);
-	box->notify_callback(box, box->notify_context);
-}
-
-static void check_timeout(struct mailbox *box)
-{
-	struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
-	struct index_notify_file *file;
-	struct stat st;
-	bool notify = FALSE;
-
-	for (file = ibox->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;
-			notify = TRUE;
-		}
-	}
-
-	if (notify)
-		notify_delay_callback(box);
-}
-
-static void notify_callback(struct mailbox *box)
-{
-	struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
-
-	timeout_reset(ibox->notify_to);
-
-	if (ibox->notify_delay_to == NULL) {
-		ibox->notify_delay_to =
-			timeout_add_short(NOTIFY_DELAY_MSECS,
-					  notify_delay_callback, box);
-	}
-}
-
-void index_mailbox_check_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 stat st;
-	struct io *io = NULL;
-
-	i_assert(set->mailbox_idle_check_interval > 0);
-
-	(void)io_add_notify(path, notify_callback, box, &io);
-
-	file = i_new(struct index_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;
-
-	/* 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 =
-			timeout_add(set->mailbox_idle_check_interval * 1000,
-				    check_timeout, box);
-	}
-}
-
-void index_mailbox_check_remove_all(struct mailbox *box)
-{
-	struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
-	struct index_notify_file *file;
-
-	while (ibox->notify_files != NULL) {
-		file = ibox->notify_files;
-		ibox->notify_files = file->next;
-
-		if (file->io_notify != NULL)
-			io_remove(&file->io_notify);
-                i_free(file->path);
-		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);
-}
diff -r 39255150d521 -r f84c81ed5d09 src/lib-storage/index/index-storage.c
--- a/src/lib-storage/index/index-storage.c	Wed Aug 19 14:47:51 2015 +0300
+++ b/src/lib-storage/index/index-storage.c	Wed Aug 19 15:12:09 2015 +0300
@@ -354,7 +354,7 @@
 {
 	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 -r 39255150d521 -r f84c81ed5d09 src/lib-storage/index/index-storage.h
--- a/src/lib-storage/index/index-storage.h	Wed Aug 19 14:47:51 2015 +0300
+++ b/src/lib-storage/index/index-storage.h	Wed Aug 19 15:12:09 2015 +0300
@@ -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 @@
 	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 @@
 /* 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 -r 39255150d521 -r f84c81ed5d09 src/lib-storage/index/index-sync.c
--- a/src/lib-storage/index/index-sync.c	Wed Aug 19 14:47:51 2015 +0300
+++ b/src/lib-storage/index/index-sync.c	Wed Aug 19 15:12:09 2015 +0300
@@ -45,8 +45,8 @@
 		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 -r 39255150d521 -r f84c81ed5d09 src/lib-storage/index/maildir/maildir-storage.c
--- a/src/lib-storage/index/maildir/maildir-storage.c	Wed Aug 19 14:47:51 2015 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Wed Aug 19 15:12:09 2015 +0300
@@ -579,11 +579,11 @@
 	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 -r 39255150d521 -r f84c81ed5d09 src/lib-storage/index/mbox/mbox-storage.c
--- a/src/lib-storage/index/mbox/mbox-storage.c	Wed Aug 19 14:47:51 2015 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Wed Aug 19 15:12:09 2015 +0300
@@ -680,9 +680,9 @@
 	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 -r 39255150d521 -r f84c81ed5d09 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Wed Aug 19 14:47:51 2015 +0300
+++ b/src/lib-storage/mail-storage-private.h	Wed Aug 19 15:12:09 2015 +0300
@@ -329,6 +329,8 @@
 	/* 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 -r 39255150d521 -r f84c81ed5d09 src/lib-storage/mailbox-watch.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-storage/mailbox-watch.c	Wed Aug 19 15:12:09 2015 +0300
@@ -0,0 +1,106 @@
+/* Copyright (c) 2002-2015 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "ioloop.h"
+#include "mail-storage-private.h"
+#include "mailbox-watch.h"
+
+#include <stdlib.h>


More information about the dovecot-cvs mailing list