dovecot-2.2: lib-storage: mailbox_get_path() and friends can now...

dovecot at dovecot.org dovecot at dovecot.org
Wed Sep 26 20:58:25 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/c7a99d41e39e
changeset: 15163:c7a99d41e39e
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Sep 26 20:50:08 2012 +0300
description:
lib-storage: mailbox_get_path() and friends can now return an error.
An upcoming "index" mailbox_list backend uses mailbox GUIDs as the directory
names. Doing a name => GUID lookup may fail, so the path lookup may fail.

This is a somewhat annoying change and perhaps it can be removed in future,
but for now it looks like it can't be avoided.

diffstat:

 src/doveadm/dsync/doveadm-dsync.c                      |   11 +-
 src/indexer/master-connection.c                        |   21 +-
 src/lib-storage/index/dbox-common/dbox-storage.c       |   19 +-
 src/lib-storage/index/dbox-multi/mdbox-map.c           |    4 +-
 src/lib-storage/index/dbox-multi/mdbox-storage.c       |    4 +-
 src/lib-storage/index/dbox-single/sdbox-file.c         |    4 +-
 src/lib-storage/index/dbox-single/sdbox-storage.c      |    2 +
 src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c |    5 +-
 src/lib-storage/index/imapc/imapc-list.c               |   11 +-
 src/lib-storage/index/index-rebuild.c                  |    4 +-
 src/lib-storage/index/index-storage.c                  |   43 +++-
 src/lib-storage/index/index-sync-pvt.c                 |   10 +-
 src/lib-storage/index/index-sync.c                     |   14 +-
 src/lib-storage/index/maildir/maildir-keywords.c       |    3 +-
 src/lib-storage/index/maildir/maildir-storage.c        |   29 ++-
 src/lib-storage/index/maildir/maildir-uidlist.c        |   13 +-
 src/lib-storage/index/maildir/maildir-util.c           |   14 +-
 src/lib-storage/index/mbox/mbox-lock.c                 |    4 +-
 src/lib-storage/index/mbox/mbox-storage.c              |   35 ++-
 src/lib-storage/index/mbox/mbox-sync.c                 |    2 +-
 src/lib-storage/index/shared/shared-list.c             |   21 +-
 src/lib-storage/index/shared/shared-storage.c          |    2 +-
 src/lib-storage/list/mailbox-list-delete.c             |   32 ++-
 src/lib-storage/list/mailbox-list-fs-flags.c           |    6 +-
 src/lib-storage/list/mailbox-list-fs-iter.c            |   15 +-
 src/lib-storage/list/mailbox-list-fs.c                 |  118 ++++++++-----
 src/lib-storage/list/mailbox-list-index.c              |    4 +-
 src/lib-storage/list/mailbox-list-maildir.c            |   78 +++++---
 src/lib-storage/list/mailbox-list-none.c               |    9 +-
 src/lib-storage/mail-storage-private.h                 |   13 +-
 src/lib-storage/mail-storage.c                         |   83 ++++++---
 src/lib-storage/mailbox-list-private.h                 |   10 +-
 src/lib-storage/mailbox-list.c                         |  139 +++++++++++-----
 src/lib-storage/mailbox-list.h                         |   23 +-
 src/plugins/acl/acl-backend-vfile-acllist.c            |   10 +-
 src/plugins/acl/acl-backend-vfile.c                    |   43 ++--
 src/plugins/acl/doveadm-acl.c                          |    6 +-
 src/plugins/fts-lucene/fts-backend-lucene.c            |    6 +-
 src/plugins/fts-squat/fts-backend-squat.c              |    4 +-
 src/plugins/fts/fts-storage.c                          |    3 +-
 src/plugins/mailbox-alias/mailbox-alias-plugin.c       |   28 ++-
 src/plugins/quota/quota-dirsize.c                      |   12 +-
 src/plugins/quota/quota-fs.c                           |   12 +-
 src/plugins/quota/quota-maildir.c                      |   40 +++-
 src/plugins/quota/quota.c                              |   10 +-
 45 files changed, 609 insertions(+), 370 deletions(-)

diffs (truncated from 2147 to 300 lines):

diff -r e3175ee39483 -r c7a99d41e39e src/doveadm/dsync/doveadm-dsync.c
--- a/src/doveadm/dsync/doveadm-dsync.c	Wed Sep 26 18:01:01 2012 +0300
+++ b/src/doveadm/dsync/doveadm-dsync.c	Wed Sep 26 20:50:08 2012 +0300
@@ -257,11 +257,12 @@
 			"virtual mailbox hierarchy separator "
 			"(specify separator for the default namespace)");
 	}
-	path1 = mailbox_list_get_root_path(user->namespaces->list,
-					   MAILBOX_LIST_PATH_TYPE_MAILBOX);
-	path2 = mailbox_list_get_root_path(user2->namespaces->list,
-					   MAILBOX_LIST_PATH_TYPE_MAILBOX);
-	if (path1 != NULL && path2 != NULL &&
+	if (mailbox_list_get_root_path(user->namespaces->list,
+				       MAILBOX_LIST_PATH_TYPE_MAILBOX,
+				       &path1) &&
+	    mailbox_list_get_root_path(user2->namespaces->list,
+				       MAILBOX_LIST_PATH_TYPE_MAILBOX,
+				       &path2) &&
 	    strcmp(path1, path2) == 0) {
 		i_fatal("Both source and destination mail_location "
 			"points to same directory: %s", path1);
diff -r e3175ee39483 -r c7a99d41e39e src/indexer/master-connection.c
--- a/src/indexer/master-connection.c	Wed Sep 26 18:01:01 2012 +0300
+++ b/src/indexer/master-connection.c	Wed Sep 26 20:50:08 2012 +0300
@@ -122,7 +122,7 @@
 	const char *path, *errstr;
 	enum mail_error error;
 	enum mailbox_sync_flags sync_flags = MAILBOX_SYNC_FLAG_FULL_READ;
-	int ret = 0;
+	int ret;
 
 	ns = mail_namespace_find(user->namespaces, mailbox);
 	if (ns == NULL) {
@@ -131,20 +131,26 @@
 	}
 
 	box = mailbox_alloc(ns->list, mailbox, 0);
-	path = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX);
-	if (*path == '\0') {
+	ret = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path);
+	if (ret <= 0) {
+		mailbox_free(&box);
+		if (ret < 0) {
+			i_error("Getting path to mailbox %s failed: %s",
+				mailbox, mailbox_get_last_error(box, NULL));
+			return -1;
+		}
 		i_info("Indexes disabled for Mailbox %s, skipping", mailbox);
-		mailbox_free(&box);
 		return 0;
 	}
-	
+	ret = 0;
+
 	if (max_recent_msgs != 0) {
 		/* index only if there aren't too many recent messages.
 		   don't bother syncing the mailbox, that alone can take a
 		   while with large maildirs. */
 		if (mailbox_open(box) < 0) {
 			i_error("Opening mailbox %s failed: %s", mailbox,
-				mail_storage_get_last_error(mailbox_get_storage(box), NULL));
+				mailbox_get_last_error(box, NULL));
 			ret = -1;
 		} else {
 			mailbox_get_open_status(box, STATUS_RECENT, &status);
@@ -159,8 +165,7 @@
 		sync_flags |= MAILBOX_SYNC_FLAG_OPTIMIZE;
 
 	if (mailbox_sync(box, sync_flags) < 0) {
-		errstr = mail_storage_get_last_error(mailbox_get_storage(box),
-						     &error);
+		errstr = mailbox_get_last_error(box, &error);
 		if (error != MAIL_ERROR_NOTFOUND) {
 			i_error("Syncing mailbox %s failed: %s",
 				mailbox, errstr);
diff -r e3175ee39483 -r c7a99d41e39e src/lib-storage/index/dbox-common/dbox-storage.c
--- a/src/lib-storage/index/dbox-common/dbox-storage.c	Wed Sep 26 18:01:01 2012 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-storage.c	Wed Sep 26 20:50:08 2012 +0300
@@ -59,10 +59,11 @@
 {
 	const char *root_dir, *alt_symlink_path, *alt_path;
 
-	root_dir = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_DIR);
+	root_dir = mailbox_list_get_root_forced(list, MAILBOX_LIST_PATH_TYPE_DIR);
 	alt_symlink_path =
 		t_strconcat(root_dir, "/"DBOX_ALT_SYMLINK_NAME, NULL);
-	alt_path = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX);
+	(void)mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX,
+					 &alt_path);
 	if (!dbox_alt_path_has_changed(root_dir, alt_path, alt_symlink_path))
 		return;
 
@@ -128,7 +129,7 @@
 {
 	const char *path;
 
-	path = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_CONTROL);
+	path = mailbox_list_get_root_forced(list, MAILBOX_LIST_PATH_TYPE_CONTROL);
 	path = t_strconcat(path, "/"DBOX_UIDVALIDITY_FILE_NAME, NULL);
 	return mailbox_uidvalidity_next(list, path);
 }
@@ -140,7 +141,9 @@
 	if (box->notify_callback == NULL)
 		index_mailbox_check_remove_all(box);
 	else {
-		dir = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX);
+		if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX,
+					&dir) <= 0)
+			return;
 		path = t_strdup_printf("%s/"DBOX_INDEX_PREFIX".log", dir);
 		index_mailbox_check_add(box, path);
 	}
@@ -250,8 +253,8 @@
 
 	/* if alt path already exists and contains files, rebuild storage so
 	   that we don't start overwriting files. */
-	alt_path = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX);
-	if (alt_path != NULL && stat(alt_path, &st) == 0) {
+	ret = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX, &alt_path);
+	if (ret > 0 && stat(alt_path, &st) == 0) {
 		ret = dir_is_empty(box->storage, alt_path);
 		if (ret < 0)
 			return -1;
@@ -289,8 +292,8 @@
 	const char *alt_path;
 	struct stat st;
 
-	alt_path = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_ALT_DIR);
-	if (alt_path == NULL)
+	if (!mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_ALT_DIR,
+					&alt_path))
 		return 0;
 
 	/* make sure alt storage is mounted. if it's not, abort the rebuild. */
diff -r e3175ee39483 -r c7a99d41e39e src/lib-storage/index/dbox-multi/mdbox-map.c
--- a/src/lib-storage/index/dbox-multi/mdbox-map.c	Wed Sep 26 18:01:01 2012 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-map.c	Wed Sep 26 20:50:08 2012 +0300
@@ -51,8 +51,8 @@
 	struct mdbox_map *map;
 	const char *root, *index_root;
 
-	root = mailbox_list_get_root_path(root_list, MAILBOX_LIST_PATH_TYPE_DIR);
-	index_root = mailbox_list_get_root_path(root_list, MAILBOX_LIST_PATH_TYPE_INDEX);
+	root = mailbox_list_get_root_forced(root_list, MAILBOX_LIST_PATH_TYPE_DIR);
+	index_root = mailbox_list_get_root_forced(root_list, MAILBOX_LIST_PATH_TYPE_INDEX);
 
 	map = i_new(struct mdbox_map, 1);
 	map->storage = storage;
diff -r e3175ee39483 -r c7a99d41e39e src/lib-storage/index/dbox-multi/mdbox-storage.c
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c	Wed Sep 26 18:01:01 2012 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c	Wed Sep 26 20:50:08 2012 +0300
@@ -52,7 +52,7 @@
 	_storage->unique_root_dir =
 		p_strdup(_storage->pool, ns->list->set.root_dir);
 
-	dir = mailbox_list_get_root_path(ns->list, MAILBOX_LIST_PATH_TYPE_DIR);
+	dir = mailbox_list_get_root_forced(ns->list, MAILBOX_LIST_PATH_TYPE_DIR);
 	storage->storage_dir = p_strconcat(_storage->pool, dir,
 					   "/"MDBOX_GLOBAL_DIR_NAME, NULL);
 	storage->alt_storage_dir = p_strconcat(_storage->pool,
@@ -203,6 +203,8 @@
 	const void *data;
 	size_t data_size;
 
+	i_assert(mbox->box.opened);
+
 	mail_index_get_header_ext(mbox->box.view, mbox->hdr_ext_id,
 				  &data, &data_size);
 	if (data_size < MDBOX_INDEX_HEADER_MIN_SIZE &&
diff -r e3175ee39483 -r c7a99d41e39e src/lib-storage/index/dbox-single/sdbox-file.c
--- a/src/lib-storage/index/dbox-single/sdbox-file.c	Wed Sep 26 18:01:01 2012 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-file.c	Wed Sep 26 20:50:08 2012 +0300
@@ -25,8 +25,8 @@
 	file->file.primary_path =
 		i_strdup_printf("%s/%s", mailbox_get_path(box), fname);
 
-	alt_path = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX);
-	if (alt_path != NULL)
+	if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX,
+				&alt_path) > 0)
 		file->file.alt_path = i_strdup_printf("%s/%s", alt_path, fname);
 }
 
diff -r e3175ee39483 -r c7a99d41e39e src/lib-storage/index/dbox-single/sdbox-storage.c
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c	Wed Sep 26 18:01:01 2012 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.c	Wed Sep 26 20:50:08 2012 +0300
@@ -124,6 +124,8 @@
 	size_t data_size;
 	int ret = 0;
 
+	i_assert(mbox->box.opened);
+
 	view = mail_index_view_open(mbox->box.index);
 	mail_index_get_header_ext(view, mbox->hdr_ext_id,
 				  &data, &data_size);
diff -r e3175ee39483 -r c7a99d41e39e src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c
--- a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c	Wed Sep 26 18:01:01 2012 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c	Wed Sep 26 20:50:08 2012 +0300
@@ -159,8 +159,9 @@
 	int ret = 0;
 
 	path = mailbox_get_path(ctx->box);
-	alt_path = mailbox_get_path_to(ctx->box,
-				       MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX);
+	if (mailbox_get_path_to(ctx->box, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX,
+				&alt_path) < 0)
+		return -1;
 
 	sdbox_sync_set_uidvalidity(ctx);
 	if (sdbox_sync_index_rebuild_dir(ctx, path, TRUE) < 0) {
diff -r e3175ee39483 -r c7a99d41e39e src/lib-storage/index/imapc/imapc-list.c
--- a/src/lib-storage/index/imapc/imapc-list.c	Wed Sep 26 18:01:01 2012 +0300
+++ b/src/lib-storage/index/imapc/imapc-list.c	Wed Sep 26 20:50:08 2012 +0300
@@ -245,9 +245,9 @@
 	return mailbox_list_get_storage_name(fs_list, vname);
 }
 
-static const char *
+static int
 imapc_list_get_path(struct mailbox_list *_list, const char *name,
-		    enum mailbox_list_path_type type)
+		    enum mailbox_list_path_type type, const char **path_r)
 {
 	struct imapc_mailbox_list *list = (struct imapc_mailbox_list *)_list;
 	struct mailbox_list *fs_list = imapc_list_get_fs(list);
@@ -255,11 +255,10 @@
 
 	if (fs_list != NULL) {
 		fs_name = imapc_list_get_fs_name(list, name);
-		return mailbox_list_get_path(fs_list, fs_name, type);
+		return mailbox_list_get_path(fs_list, fs_name, type, path_r);
 	} else {
-		if (type == MAILBOX_LIST_PATH_TYPE_INDEX)
-			return "";
-		return NULL;
+		*path_r = NULL;
+		return 0;
 	}
 }
 
diff -r e3175ee39483 -r c7a99d41e39e src/lib-storage/index/index-rebuild.c
--- a/src/lib-storage/index/index-rebuild.c	Wed Sep 26 18:01:01 2012 +0300
+++ b/src/lib-storage/index/index-rebuild.c	Wed Sep 26 20:50:08 2012 +0300
@@ -167,7 +167,9 @@
 	mail_cache_reset(box->cache);
 
 	/* if backup index file exists, try to use it */
-	index_dir = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX);
+	if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX,
+				&index_dir) <= 0)
+		i_unreached();
 	backup_path = t_strconcat(box->index_prefix, "/.backup", NULL);
 	ctx->backup_index = mail_index_alloc(index_dir, backup_path);
 
diff -r e3175ee39483 -r c7a99d41e39e src/lib-storage/index/index-storage.c
--- a/src/lib-storage/index/index-storage.c	Wed Sep 26 18:01:01 2012 +0300
+++ b/src/lib-storage/index/index-storage.c	Wed Sep 26 20:50:08 2012 +0300
@@ -134,19 +134,21 @@
 	ibox->last_notify_type = MAILBOX_LOCK_NOTIFY_NONE;
 }
 
-static struct mail_index *
-index_mailbox_alloc_index(struct mailbox *box)
+static int
+index_mailbox_alloc_index(struct mailbox *box, struct mail_index **index_r)
 {
 	const char *index_dir, *mailbox_path;
 
-	mailbox_path = mailbox_get_path(box);
-	index_dir = (box->flags & MAILBOX_FLAG_NO_INDEX_FILES) != 0 ? "" :
-		mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX);
-	if (*index_dir == '\0')
+	if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_MAILBOX,
+				&mailbox_path) < 0)
+		return -1;
+	if ((box->flags & MAILBOX_FLAG_NO_INDEX_FILES) != 0 ||
+	    mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX,
+				&index_dir) <= 0)
 		index_dir = NULL;
-
-	return mail_index_alloc_cache_get(mailbox_path, index_dir,
-					  box->index_prefix);
+	*index_r = mail_index_alloc_cache_get(mailbox_path, index_dir,
+					      box->index_prefix);
+	return 0;
 }
 
 int index_storage_mailbox_exists(struct mailbox *box,
@@ -161,9 +163,17 @@
 {
 	struct stat st;
 	const char *path, *path2;
+	int ret;
 
 	/* see if it's selectable */
-	path = mailbox_get_path(box);
+	ret = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_MAILBOX, &path);
+	if (ret < 0)
+		return -1;
+	if (ret == 0) {


More information about the dovecot-cvs mailing list