dovecot-2.0: virtual: Don't unnecessarily stat() the virtual dir...

dovecot at dovecot.org dovecot at dovecot.org
Wed Sep 29 18:35:01 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/e140d7aab969
changeset: 12201:e140d7aab969
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Sep 29 16:34:56 2010 +0100
description:
virtual: Don't unnecessarily stat() the virtual directory.
Its existence is checked automatically when trying to open dovecot-virtual file.

diffstat:

 src/plugins/virtual/virtual-config.c  |  31 ++++++++++++++++++++-----------
 src/plugins/virtual/virtual-storage.c |  18 ------------------
 2 files changed, 20 insertions(+), 29 deletions(-)

diffs (118 lines):

diff -r 5db6b49f31c4 -r e140d7aab969 src/plugins/virtual/virtual-config.c
--- a/src/plugins/virtual/virtual-config.c	Wed Sep 29 16:33:12 2010 +0100
+++ b/src/plugins/virtual/virtual-config.c	Wed Sep 29 16:34:56 2010 +0100
@@ -324,8 +324,9 @@
 
 int virtual_config_read(struct virtual_mailbox *mbox)
 {
-	struct mail_user *user = mbox->storage->storage.user;
+	struct mail_storage *storage = mbox->box.storage;
 	struct virtual_parse_context ctx;
+	struct stat st;
 	const char *path, *line, *error;
 	unsigned int linenum = 0;
 	int fd, ret = 0;
@@ -336,19 +337,27 @@
 	path = t_strconcat(mbox->box.path, "/"VIRTUAL_CONFIG_FNAME, NULL);
 	fd = open(path, O_RDONLY);
 	if (fd == -1) {
-		if (errno == ENOENT) {
-			mail_storage_set_error(mbox->box.storage,
-				MAIL_ERROR_NOTPOSSIBLE,
+		if (errno == EACCES) {
+			mail_storage_set_critical(storage, "%s",
+				mail_error_eacces_msg("stat", mbox->box.path));
+		} else if (errno != ENOENT) {
+			mail_storage_set_critical(storage,
+						  "open(%s) failed: %m", path);
+		} else if (stat(mbox->box.path, &st) == 0) {
+			mail_storage_set_error(storage, MAIL_ERROR_NOTPOSSIBLE,
 				"Virtual mailbox missing configuration file");
-			return -1;
+		} else if (errno == ENOENT) {
+			mail_storage_set_error(storage, MAIL_ERROR_NOTFOUND,
+				T_MAIL_ERR_MAILBOX_NOT_FOUND(mbox->box.name));
+		} else {
+			mail_storage_set_critical(storage,
+				"stat(%s) failed: %m", mbox->box.path);
 		}
-		mail_storage_set_critical(mbox->box.storage,
-					  "open(%s) failed: %m", path);
 		return -1;
 	}
 
 	memset(&ctx, 0, sizeof(ctx));
-	ctx.sep = mail_namespaces_get_root_sep(user->namespaces);
+	ctx.sep = mail_namespaces_get_root_sep(storage->user->namespaces);
 	ctx.mbox = mbox;
 	ctx.pool = mbox->box.pool;
 	ctx.rule = t_str_new(256);
@@ -363,7 +372,7 @@
 		else
 			ret = virtual_config_parse_line(&ctx, line, &error);
 		if (ret < 0) {
-			mail_storage_set_critical(mbox->box.storage,
+			mail_storage_set_critical(storage,
 						  "%s: Error at line %u: %s",
 						  path, linenum, error);
 			break;
@@ -372,7 +381,7 @@
 	if (ret == 0) {
 		ret = virtual_config_add_rule(&ctx, &error);
 		if (ret < 0) {
-			mail_storage_set_critical(mbox->box.storage,
+			mail_storage_set_critical(storage,
 						  "%s: Error at line %u: %s",
 						  path, linenum, error);
 		}
@@ -383,7 +392,7 @@
 		ret = virtual_config_expand_wildcards(&ctx);
 
 	if (ret == 0 && array_count(&mbox->backend_boxes) == 0) {
-		mail_storage_set_critical(mbox->box.storage,
+		mail_storage_set_critical(storage,
 					  "%s: No mailboxes defined", path);
 		ret = -1;
 	}
diff -r 5db6b49f31c4 -r e140d7aab969 src/plugins/virtual/virtual-storage.c
--- a/src/plugins/virtual/virtual-storage.c	Wed Sep 29 16:33:12 2010 +0100
+++ b/src/plugins/virtual/virtual-storage.c	Wed Sep 29 16:34:56 2010 +0100
@@ -271,7 +271,6 @@
 static int virtual_mailbox_open(struct mailbox *box)
 {
 	struct virtual_mailbox *mbox = (struct virtual_mailbox *)box;
-	struct stat st;
 	int ret = 0;
 
 	if (virtual_mailbox_is_in_open_stack(mbox->storage, box->name)) {
@@ -280,22 +279,6 @@
 		return -1;
 	}
 
-	if (stat(box->path, &st) == 0) {
-		/* exists, open it */
-	} else if (errno == ENOENT) {
-		mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
-			T_MAIL_ERR_MAILBOX_NOT_FOUND(box->name));
-		return -1;
-	} else if (errno == EACCES) {
-		mail_storage_set_critical(box->storage, "%s",
-			mail_error_eacces_msg("stat", box->path));
-		return -1;
-	} else {
-		mail_storage_set_critical(box->storage,
-					  "stat(%s) failed: %m", box->path);
-		return -1;
-	}
-
 	if (!array_is_created(&mbox->backend_boxes))
 		ret = virtual_config_read(mbox);
 	if (ret == 0) {
@@ -304,7 +287,6 @@
 		array_delete(&mbox->storage->open_stack,
 			     array_count(&mbox->storage->open_stack)-1, 1);
 	}
-
 	if (ret < 0) {
 		virtual_mailbox_close_internal(mbox);
 		return -1;


More information about the dovecot-cvs mailing list