[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-expunge.c,1.23,1.24 mbox-list.c,1.7,1.8 mbox-save.c,1.28,1.29 mbox-storage.c,1.23,1.24

cras at procontrol.fi cras at procontrol.fi
Fri Dec 20 09:53:54 EET 2002


Update of /home/cvs/dovecot/src/lib-storage/index/mbox
In directory danu:/tmp/cvs-serv29331/src/lib-storage/index/mbox

Modified Files:
	mbox-expunge.c mbox-list.c mbox-save.c mbox-storage.c 
Log Message:
Added :INDEX=<dir> for both Maildir and mbox to specify different location
where to store index files. This would allow keeping mailboxes accessible
through NFS but still keep the indexes in fast local disk.

Did also some other related cleanups and minor fixes.



Index: mbox-expunge.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-expunge.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- mbox-expunge.c	6 Dec 2002 01:09:23 -0000	1.23
+++ mbox-expunge.c	20 Dec 2002 07:53:52 -0000	1.24
@@ -142,7 +142,7 @@
 	if (ftruncate(ibox->index->mbox_fd, (off_t)output->offset) < 0) {
 		mail_storage_set_error(ibox->box.storage, "ftruncate() failed "
 				       "for mbox file %s: %m",
-				       ibox->index->mbox_path);
+				       ibox->index->mailbox_path);
 		failed = TRUE;
 	}
 

Index: mbox-list.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-list.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mbox-list.c	20 Dec 2002 06:00:07 -0000	1.7
+++ mbox-list.c	20 Dec 2002 07:53:52 -0000	1.8
@@ -110,7 +110,9 @@
 
 		if (S_ISDIR(st.st_mode)) {
 			/* subdirectory, scan it too */
+			t_push();
 			func(storage, listpath, MAILBOX_NOSELECT, context);
+			t_pop();
 
 			if (!mbox_find_path(storage, glob, func,
 					    context, listpath)) {
@@ -119,7 +121,9 @@
 			}
 		} else if (match > 0 &&
 			   strcmp(fullpath, storage->inbox_file) != 0) {
+			t_push();
 			func(storage, listpath, MAILBOX_NOINFERIORS, context);
+			t_pop();
 		}
 	}
 

Index: mbox-save.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-save.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- mbox-save.c	19 Dec 2002 01:53:19 -0000	1.28
+++ mbox-save.c	20 Dec 2002 07:53:52 -0000	1.29
@@ -183,7 +183,7 @@
 		return FALSE;
 
 	index = ibox->index;
-	mbox_path = index->mbox_path;
+	mbox_path = index->mailbox_path;
 	if (!mbox_seek_to_end(box->storage, index->mbox_fd, mbox_path, &pos))
 		failed = TRUE;
 	else {

Index: mbox-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- mbox-storage.c	20 Dec 2002 06:00:07 -0000	1.23
+++ mbox-storage.c	20 Dec 2002 07:53:52 -0000	1.24
@@ -72,10 +72,10 @@
 static MailStorage *mbox_create(const char *data, const char *user)
 {
 	MailStorage *storage;
-	const char *root_dir, *inbox_file, *p;
+	const char *root_dir, *inbox_file, *index_dir, *p;
 	struct stat st;
 
-	root_dir = inbox_file = NULL;
+	root_dir = inbox_file = index_dir = NULL;
 
 	if (data == NULL || *data == '\0') {
 		/* we'll need to figure out the mail location ourself.
@@ -83,8 +83,8 @@
 		   either $HOME/mail or $HOME/Mail */
 		root_dir = get_root_dir();
 	} else {
-		/* <root folder> | <INBOX path> [:INBOX=<path>]
-		   [:<reserved for future>] */
+		/* <root folder> | <INBOX path>
+		   [:INBOX=<path>] [:INDEX=<dir>] */
 		p = strchr(data, ':');
 		if (p == NULL) {
 			if (stat(data, &st) == 0 && S_ISDIR(st.st_mode))
@@ -95,8 +95,14 @@
 			}
 		} else {
 			root_dir = t_strdup_until(data, p);
-			if (strncmp(p+1, "INBOX=", 6) == 0)
-				inbox_file = t_strcut(p+7, ':');
+			do {
+				p++;
+				if (strncmp(p, "INBOX=", 6) == 0)
+					inbox_file = t_strcut(p+6, ':');
+				else if (strncmp(p, "INDEX=", 6) == 0)
+					index_dir = t_strcut(p+6, ':');
+				p = strchr(p, ':');
+			} while (p != NULL);
 		}
 	}
 
@@ -105,12 +111,15 @@
 
 	if (inbox_file == NULL)
 		inbox_file = t_strconcat(root_dir, "/inbox", NULL);
+	if (index_dir == NULL)
+		index_dir = root_dir;
 
 	storage = i_new(MailStorage, 1);
 	memcpy(storage, &mbox_storage, sizeof(MailStorage));
 
 	storage->dir = i_strdup(root_dir);
 	storage->inbox_file = i_strdup(inbox_file);
+	storage->index_dir = i_strdup(index_dir);
 	storage->user = i_strdup(user);
 	storage->callbacks = i_new(MailStorageCallbacks, 1);
 	return storage;
@@ -118,9 +127,12 @@
 
 static void mbox_free(MailStorage *storage)
 {
-	i_free(storage->callbacks);
 	i_free(storage->dir);
+	i_free(storage->inbox_file);
+	i_free(storage->index_dir);
 	i_free(storage->user);
+	i_free(storage->error);
+	i_free(storage->callbacks);
 	i_free(storage);
 }
 
@@ -149,24 +161,25 @@
 		mbox_is_valid_mask(name);
 }
 
-static const char *mbox_get_index_dir(const char *mbox_path)
+static const char *mbox_get_index_dir(MailStorage *storage, const char *name)
 {
-	const char *p, *rootpath;
+	const char *p;
 
-	p = strrchr(mbox_path, '/');
+	p = strrchr(name, '/');
 	if (p == NULL)
-		return t_strconcat(".imap/", mbox_path, NULL);
+		return t_strconcat(storage->index_dir, "/.imap/", name, NULL);
 	else {
-		rootpath = t_strdup_until(mbox_path, p);
-		return t_strconcat(rootpath, "/.imap/", p+1, NULL);
+		return t_strconcat(storage->index_dir, t_strdup_until(name, p),
+				   "/.imap/", p+1, NULL);
 	}
 }
 
-static int create_mbox_index_dirs(const char *mbox_path, int verify)
+static int create_mbox_index_dirs(MailStorage *storage, const char *name,
+				  int verify)
 {
 	const char *index_dir, *imap_dir;
 
-	index_dir = mbox_get_index_dir(mbox_path);
+	index_dir = mbox_get_index_dir(storage, name);
 	imap_dir = t_strdup_until(index_dir, strstr(index_dir, ".imap/") + 5);
 
 	if (mkdir(imap_dir, CREATE_MODE) == -1 && errno != EEXIST)
@@ -179,7 +192,6 @@
 
 static void verify_inbox(MailStorage *storage)
 {
-	const char *index_dir;
 	int fd;
 
 	/* make sure inbox file itself exists */
@@ -188,8 +200,7 @@
 		(void)close(fd);
 
 	/* make sure the index directories exist */
-	index_dir = t_strconcat(storage->dir, "/INBOX", NULL);
-	(void)create_mbox_index_dirs(index_dir, TRUE);
+	(void)create_mbox_index_dirs(storage, "INBOX", TRUE);
 }
 
 static const char *mbox_get_path(MailStorage *storage, const char *name)
@@ -212,14 +223,13 @@
 		   path = "<inbox_file>/INBOX"
 		   index_dir = "/mail/.imap/INBOX" */
 		path = storage->inbox_file;
-		index_dir = mbox_get_index_dir(t_strconcat(storage->dir,
-							   "/INBOX", NULL));
+		index_dir = mbox_get_index_dir(storage, "/INBOX");
 	} else {
 		/* name = "foo/bar"
 		   path = "/mail/foo/bar"
 		   index_dir = "/mail/foo/.imap/bar" */
 		path = mbox_get_path(storage, name);
-		index_dir = mbox_get_index_dir(path);
+		index_dir = mbox_get_index_dir(storage, name);
 	}
 
 	index = index_storage_lookup_ref(index_dir);
@@ -232,7 +242,7 @@
 				  name, readonly, fast);
 	if (ibox != NULL) {
 		ibox->expunge_locked = mbox_expunge_locked;
-		index_mailbox_check_add(ibox, index->mbox_path);
+		index_mailbox_check_add(ibox, index->mailbox_path);
 	}
 	return (Mailbox *) ibox;
 }
@@ -260,7 +270,7 @@
 	path = mbox_get_path(storage, name);
 	if (stat(path, &st) == 0) {
 		/* exists - make sure the required directories are also there */
-		(void)create_mbox_index_dirs(path, TRUE);
+		(void)create_mbox_index_dirs(storage, name, TRUE);
 
 		return mbox_open(storage, name, readonly, fast);
 	} else if (errno == ENOENT) {
@@ -351,7 +361,7 @@
 	}
 
 	/* next delete the index directory */
-	index_dir = mbox_get_index_dir(path);
+	index_dir = mbox_get_index_dir(storage, name);
 	if (!unlink_directory(index_dir) && errno != ENOENT) {
 		mail_storage_set_critical(storage, "unlink_directory(%s) "
 					  "failed: %m", index_dir);
@@ -394,8 +404,8 @@
 	}
 
 	/* we need to rename the index directory as well */
-	old_indexdir = mbox_get_index_dir(oldpath);
-	new_indexdir = mbox_get_index_dir(newpath);
+	old_indexdir = mbox_get_index_dir(storage, oldname);
+	new_indexdir = mbox_get_index_dir(storage, newname);
 	(void)rename(old_indexdir, new_indexdir);
 
 	return TRUE;
@@ -464,6 +474,7 @@
 	mbox_get_mailbox_name_status,
 	mail_storage_get_last_error,
 
+	NULL,
 	NULL,
 	NULL,
 	NULL,




More information about the dovecot-cvs mailing list