changeset 5194:7b0749edc553 HEAD

KEEP_LOCK: When using dotlock, touch it every 10 seconds.
author Timo Sirainen <tss@iki.fi>
date Thu, 22 Feb 2007 19:29:46 +0200
parents 7da5b23bed2d
children 840d177c468f
files src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/index/mbox/mbox-storage.h
diffstat 2 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-storage.c	Thu Feb 22 18:12:10 2007 +0200
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Thu Feb 22 19:29:46 2007 +0200
@@ -1,6 +1,7 @@
 /* Copyright (C) 2002-2003 Timo Sirainen */
 
 #include "lib.h"
+#include "ioloop.h"
 #include "array.h"
 #include "istream.h"
 #include "mkdir-parents.h"
@@ -20,6 +21,9 @@
 
 #define CREATE_MODE 0770 /* umask() should limit it more */
 
+/* How often to touch the dotlock file when using KEEP_LOCKED flag */
+#define MBOX_LOCK_TOUCH_MSECS (10*1000)
+
 /* Assume that if atime < mtime, there are new mails. If it's good enough for
    UW-IMAP, it's good enough for us. */
 #define STAT_GET_MARKED(st) \
@@ -516,6 +520,11 @@
 	return st.st_size / 1024 < min_size;
 }
 
+static void mbox_lock_touch_timeout(struct mbox_mailbox *mbox)
+{
+	(void)file_dotlock_touch(mbox->mbox_dotlock);
+}
+
 static struct mbox_mailbox *
 mbox_alloc(struct mbox_storage *storage, struct mail_index *index,
 	   const char *name, const char *path, enum mailbox_open_flags flags)
@@ -554,6 +563,12 @@
 			mailbox_close(&box);
 			return NULL;
 		}
+
+		if (mbox->mbox_dotlock != NULL) {
+			mbox->keep_lock_to =
+				timeout_add(MBOX_LOCK_TOUCH_MSECS,
+					    mbox_lock_touch_timeout, mbox);
+		}
 	}
 
 	index_storage_mailbox_init(&mbox->ibox, name, flags,
@@ -967,6 +982,8 @@
 
 	if (mbox->mbox_global_lock_id != 0)
 		(void)mbox_unlock(mbox, mbox->mbox_global_lock_id);
+	if (mbox->keep_lock_to != NULL)
+		timeout_remove(&mbox->keep_lock_to);
 
         mbox_file_close(mbox);
 	if (mbox->mbox_file_stream != NULL)
--- a/src/lib-storage/index/mbox/mbox-storage.h	Thu Feb 22 18:12:10 2007 +0200
+++ b/src/lib-storage/index/mbox/mbox-storage.h	Thu Feb 22 19:29:46 2007 +0200
@@ -39,6 +39,7 @@
 	unsigned int mbox_excl_locks, mbox_shared_locks;
 	struct dotlock *mbox_dotlock;
 	unsigned int mbox_lock_id, mbox_global_lock_id;
+	struct timeout *keep_lock_to;
 	bool mbox_readonly, mbox_writeonly;
 	time_t mbox_dirty_stamp;
 	off_t mbox_dirty_size;