[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-storage.c, 1.155, 1.156 mbox-storage.h, 1.46, 1.47

tss at dovecot.org tss at dovecot.org
Fri Dec 1 20:55:07 UTC 2006


Update of /var/lib/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv10052/index/mbox

Modified Files:
	mbox-storage.c mbox-storage.h 
Log Message:
Removed get_mailbox_control_dir and get_mailbox_index_dir virtual functions
from mail_storage, since they're already in mailbox_list.get_path(). Updated
mbox to override that function to return index/control dirs with the
".imap/" in the middle.



Index: mbox-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.c,v
retrieving revision 1.155
retrieving revision 1.156
diff -u -d -r1.155 -r1.156
--- mbox-storage.c	25 Nov 2006 22:17:45 -0000	1.155
+++ mbox-storage.c	1 Dec 2006 20:55:05 -0000	1.156
@@ -1,7 +1,7 @@
 /* Copyright (C) 2002-2003 Timo Sirainen */
 
 #include "lib.h"
-#include "buffer.h"
+#include "array.h"
 #include "istream.h"
 #include "mkdir-parents.h"
 #include "unlink-directory.h"
@@ -45,6 +45,9 @@
 extern struct mail_storage mbox_storage;
 extern struct mailbox mbox_mailbox;
 
+static bool mbox_mailbox_list_module_id_set = FALSE;
+static unsigned int mbox_mailbox_list_module_id;
+
 int mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function)
 {
 	i_assert(function != NULL);
@@ -345,6 +348,28 @@
 	return 0;
 }
 
+static const char *
+mbox_list_get_path(struct mailbox_list *list, const char *name,
+		   enum mailbox_list_path_type type)
+{
+	struct mbox_storage *storage =
+		*((void **)array_idx_modifiable(&list->module_contexts,
+						mbox_mailbox_list_module_id));
+	const char *path, *p;
+
+	path = storage->list_super.get_path(list, name, type);
+	if (type == MAILBOX_LIST_PATH_TYPE_CONTROL ||
+	    type == MAILBOX_LIST_PATH_TYPE_INDEX) {
+		p = strrchr(path, '/');
+		if (p == NULL)
+			return "";
+
+		return t_strconcat(t_strdup_until(path, p),
+				   "/"MBOX_INDEX_DIR_NAME"/", p+1, NULL);
+	}
+	return path;
+}
+
 static struct mail_storage *
 mbox_create(const char *data, const char *user, enum mail_storage_flags flags,
 	    enum mail_storage_lock_method lock_method)
@@ -373,6 +398,16 @@
 		return NULL;
 	}
 
+	storage->list_super = list->v;
+	list->v.get_path = mbox_list_get_path;
+
+	if (!mbox_mailbox_list_module_id_set) {
+		mbox_mailbox_list_module_id_set = TRUE;
+		mbox_mailbox_list_module_id = mailbox_list_module_id++;
+	}
+	array_idx_set(&list->module_contexts,
+		      mbox_mailbox_list_module_id, &storage);
+
 	istorage = INDEX_STORAGE(storage);
 	istorage->storage = mbox_storage;
 	istorage->storage.pool = pool;
@@ -391,31 +426,14 @@
 	pool_unref(storage->storage.pool);
 }
 
-static const char *
-mbox_get_index_dir(struct mail_storage *storage, const char *name)
-{
-	const char *dir, *p;
-
-	dir = mailbox_list_get_path(storage->list, name,
-				    MAILBOX_LIST_PATH_TYPE_INDEX);
-	if (*dir == '\0')
-		return NULL;
-
-	p = strrchr(dir, '/');
-	if (p == NULL)
-		return NULL;
-
-	return t_strconcat(t_strdup_until(dir, p),
-			   "/"MBOX_INDEX_DIR_NAME"/", p+1, NULL);
-}
-
 static int create_mbox_index_dirs(struct mail_storage *storage,
 				  const char *name)
 {
 	const char *index_dir;
 
-	index_dir = mbox_get_index_dir(storage, name);
-	if (index_dir == NULL)
+	index_dir = mailbox_list_get_path(storage->list, name,
+					  MAILBOX_LIST_PATH_TYPE_INDEX);
+	if (*index_dir == '\0')
 		return 0;
 
 	if (mkdir_parents(index_dir, CREATE_MODE) < 0) {
@@ -527,7 +545,8 @@
 
 	path = mailbox_list_get_path(_storage->list, name,
 				     MAILBOX_LIST_PATH_TYPE_MAILBOX);
-	index_dir = mbox_get_index_dir(_storage, name);
+	index_dir = mailbox_list_get_path(_storage->list, name,
+					  MAILBOX_LIST_PATH_TYPE_INDEX);
 
 	if ((flags & MAILBOX_OPEN_NO_INDEX_FILES) != 0)
 		index_dir = "";
@@ -580,9 +599,10 @@
 	path = mailbox_list_get_path(_storage->list, name,
 				     MAILBOX_LIST_PATH_TYPE_MAILBOX);
 	if ((flags & MAILBOX_OPEN_NO_INDEX_FILES) != 0)
-		index_dir = NULL;
+		index_dir = "";
 	else {
-		index_dir = mbox_get_index_dir(_storage, name);
+		index_dir = mailbox_list_get_path(_storage->list, name,
+						  MAILBOX_LIST_PATH_TYPE_INDEX);
 
 		/* make sure the required directories are also there */
 		if (create_mbox_index_dirs(_storage, name) < 0)
@@ -799,8 +819,9 @@
 
 	/* delete the index directory first, so that if we crash we don't
 	   leave indexes for deleted mailboxes lying around */
-	index_dir = mbox_get_index_dir(_storage, name);
-	if (index_dir != NULL) {
+	index_dir = mailbox_list_get_path(_storage->list, name,
+					  MAILBOX_LIST_PATH_TYPE_INDEX);
+	if (*index_dir != '\0') {
 		index_storage_destroy_unrefed();
 
 		if (unlink_directory(index_dir, TRUE) < 0 && errno != ENOENT) {
@@ -897,9 +918,11 @@
 	}
 
 	/* we need to rename the index directory as well */
-	old_indexdir = mbox_get_index_dir(_storage, oldname);
-	new_indexdir = mbox_get_index_dir(_storage, newname);
-	if (old_indexdir != NULL) {
+	old_indexdir = mailbox_list_get_path(_storage->list, oldname,
+					     MAILBOX_LIST_PATH_TYPE_INDEX);
+	new_indexdir = mailbox_list_get_path(_storage->list, newname,
+					     MAILBOX_LIST_PATH_TYPE_INDEX);
+	if (*old_indexdir != '\0') {
 		if (rename(old_indexdir, new_indexdir) < 0 &&
 		    errno != ENOENT) {
 			mail_storage_set_critical(_storage,
@@ -1038,8 +1061,6 @@
 		mbox_free,
 		mbox_autodetect,
 		index_storage_set_callbacks,
-		mbox_get_index_dir,
-		mbox_get_index_dir,
 		mbox_mailbox_open,
 		mbox_mailbox_create,
 		mbox_mailbox_delete,

Index: mbox-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.h,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- mbox-storage.h	16 Nov 2006 00:16:35 -0000	1.46
+++ mbox-storage.h	1 Dec 2006 20:55:05 -0000	1.47
@@ -12,6 +12,7 @@
 #define MBOX_INDEX_DIR_NAME ".imap"
 
 #include "index-storage.h"
+#include "mailbox-list-private.h"
 
 #define STORAGE(mbox_storage) \
 	(&(mbox_storage)->storage.storage)
@@ -20,6 +21,8 @@
 
 struct mbox_storage {
 	struct index_storage storage;
+
+	struct mailbox_list_vfuncs list_super;
 };
 
 struct mbox_mailbox {



More information about the dovecot-cvs mailing list