changeset 4859:92c0994a1fcf HEAD

Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage creation if the root directory doesn't exist. Otherwise the root dir is created.
author Timo Sirainen <tss@iki.fi>
date Sun, 03 Dec 2006 15:29:56 +0200
parents 69a2b3d5f00d
children 87ae4d41bc10
files src/lib-storage/index/dbox/dbox-storage.c src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/mail-storage.h
diffstat 4 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-storage.c	Sun Dec 03 14:47:52 2006 +0200
+++ b/src/lib-storage/index/dbox/dbox-storage.c	Sun Dec 03 15:29:56 2006 +0200
@@ -89,6 +89,7 @@
 	struct mailbox_list_settings list_set;
 	struct mailbox_list *list;
 	const char *error;
+	struct stat st;
 	pool_t pool;
 
 	if (dbox_get_list_settings(&list_set, data, flags) < 0)
@@ -96,6 +97,16 @@
 	list_set.mail_storage_flags = &flags;
 	list_set.mail_storage_lock_method = &lock_method;
 
+	if ((flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) {
+		if (stat(list_set.root_dir, &st) < 0) {
+			if (errno != ENOENT) {
+				i_error("stat(%s) failed: %m",
+					list_set.root_dir);
+			}
+			return NULL;
+		}
+	}
+
 	if (mkdir_parents(list_set.root_dir, CREATE_MODE) < 0 &&
 	    errno != EEXIST) {
 		i_error("mkdir_parents(%s) failed: %m", list_set.root_dir);
--- a/src/lib-storage/index/maildir/maildir-storage.c	Sun Dec 03 14:47:52 2006 +0200
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Sun Dec 03 15:29:56 2006 +0200
@@ -144,6 +144,7 @@
 	struct mailbox_list_settings list_set;
 	struct mailbox_list *list;
 	const char *error;
+	struct stat st;
 	pool_t pool;
 
 	if (maildir_get_list_settings(&list_set, data, flags) < 0)
@@ -151,6 +152,17 @@
 	list_set.mail_storage_flags = &flags;
 	list_set.mail_storage_lock_method = &lock_method;
 
+	/* normally the maildir is created in verify_inbox() */
+	if ((flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) {
+		if (stat(list_set.root_dir, &st) < 0) {
+			if (errno != ENOENT) {
+				i_error("stat(%s) failed: %m",
+					list_set.root_dir);
+			}
+			return NULL;
+		}
+	}
+
 	pool = pool_alloconly_create("storage", 512);
 	storage = p_new(pool, struct maildir_storage, 1);
 
--- a/src/lib-storage/index/mbox/mbox-storage.c	Sun Dec 03 14:47:52 2006 +0200
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Sun Dec 03 15:29:56 2006 +0200
@@ -310,6 +310,9 @@
 	}
 
 	if (list_set->root_dir == NULL) {
+		if ((flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0)
+			return -1;
+
 		list_set->root_dir = create_root_dir(debug);
 		if (list_set->root_dir == NULL)
 			return -1;
@@ -329,6 +332,8 @@
 		} else if (errno != ENOENT && errno != ENOTDIR) {
 			i_error("lstat(%s) failed: %m", list_set->root_dir);
 			return -1;
+		} else if ((flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) {
+			return -1;
 		} else if (mkdir_parents(list_set->root_dir, CREATE_MODE) < 0 &&
 			   errno != EEXIST) {
 			i_error("mkdir_parents(%s) failed: %m",
--- a/src/lib-storage/mail-storage.h	Sun Dec 03 14:47:52 2006 +0200
+++ b/src/lib-storage/mail-storage.h	Sun Dec 03 15:29:56 2006 +0200
@@ -28,8 +28,11 @@
 	/* Don't try to autodetect anything, require that the given data 
 	   contains all the necessary information. */
 	MAIL_STORAGE_FLAG_NO_AUTODETECTION	= 0x100,
+	/* Don't autocreate any directories. If they don't exist,
+	   fail to create the storage. */
+	MAIL_STORAGE_FLAG_NO_AUTOCREATE		= 0x200,
 	/* Ths storage contains INBOX */
-	MAIL_STORAGE_FLAG_HAS_INBOX		= 0x200
+	MAIL_STORAGE_FLAG_HAS_INBOX		= 0x400
 };
 
 enum mail_storage_lock_method {