diff src/lib-storage/index/dbox-common/dbox-storage.c @ 10653:5fe70b5da1b8 HEAD

lib-storage: Moved mailbox directory creation code to mailbox_list backend.
author Timo Sirainen <tss@iki.fi>
date Sun, 07 Feb 2010 01:50:49 +0200
parents bdb1ea37ccee
children 56b1d4dd9c7d
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-common/dbox-storage.c	Sat Feb 06 23:41:33 2010 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-storage.c	Sun Feb 07 01:50:49 2010 +0200
@@ -157,48 +157,17 @@
 int dbox_mailbox_create(struct mailbox *box,
 			const struct mailbox_update *update, bool directory)
 {
-	const char *path, *alt_path, *origin;
-	struct stat st;
+	struct dbox_storage *storage = (struct dbox_storage *)box->storage;
 
-	path = mailbox_list_get_path(box->list, box->name,
-				     directory ? MAILBOX_LIST_PATH_TYPE_DIR :
-				     MAILBOX_LIST_PATH_TYPE_MAILBOX);
-	if (stat(path, &st) == 0) {
-		mail_storage_set_error(box->storage, MAIL_ERROR_EXISTS,
-				       "Mailbox already exists");
-		return -1;
-	}
-
-	if (directory) {
-		mode_t mode;
-		gid_t gid;
+	if (directory &&
+	    (box->list->props & MAILBOX_LIST_PROP_NO_NOSELECT) == 0)
+		return 0;
 
-		mailbox_list_get_dir_permissions(box->list, NULL, &mode,
-						 &gid, &origin);
-		if (mkdir_parents_chgrp(path, mode, gid, origin) == 0)
-			return 0;
-		else if (errno == EEXIST) {
-			mail_storage_set_error(box->storage, MAIL_ERROR_EXISTS,
-					       "Mailbox already exists");
-		} else if (!mail_storage_set_error_from_errno(box->storage)) {
-			mail_storage_set_critical(box->storage,
-						  "mkdir(%s) failed: %m", path);
-		}
+	if (index_storage_mailbox_open(box) < 0)
 		return -1;
-	}
-
-	/* make sure the alt path doesn't exist yet. it shouldn't (except with
-	   race conditions with RENAME/DELETE), but if something crashed and
-	   left it lying around we don't want to start overwriting files in
-	   it. */
-	alt_path = dbox_get_alt_path(box->list, path);
-	if (alt_path != NULL && stat(alt_path, &st) == 0) {
-		mail_storage_set_error(box->storage, MAIL_ERROR_EXISTS,
-				       "Mailbox already exists");
+	if (storage->v.mailbox_create_indexes(box, update) < 0)
 		return -1;
-	}
-
-	return dbox_mailbox_create_indexes(box, update);
+	return 0;
 }
 
 int dbox_list_iter_is_mailbox(struct mailbox_list_iterate_context *ctx ATTR_UNUSED,