changeset 15038:92cc78c5dc77

lib-storage: Removed rename_children parameter from mailbox_rename() The children are now always renamed. The only reason this feature was added in the first place was to make dsync's job easier, but this is no longer needed.
author Timo Sirainen <tss@iki.fi>
date Mon, 10 Sep 2012 17:19:43 +0300
parents 920756cd29b8
children 349d52c4ca51
files src/doveadm/doveadm-mail-mailbox.c src/doveadm/dsync/dsync-brain-mailbox-tree-sync.c src/imap/cmd-rename.c src/lib-storage/fail-mailbox.c src/lib-storage/index/imapc/imapc-list.c src/lib-storage/index/index-storage.c src/lib-storage/index/index-storage.h src/lib-storage/index/shared/shared-list.c src/lib-storage/list/mailbox-list-fs.c src/lib-storage/list/mailbox-list-index.c src/lib-storage/list/mailbox-list-maildir.c src/lib-storage/list/mailbox-list-none.c src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h src/lib-storage/mailbox-list-private.h src/plugins/acl/acl-mailbox.c src/plugins/lazy-expunge/lazy-expunge-plugin.c src/plugins/mail-log/mail-log-plugin.c src/plugins/notify/notify-plugin-private.h src/plugins/notify/notify-plugin.c src/plugins/notify/notify-plugin.h src/plugins/notify/notify-storage.c src/plugins/replication/replication-plugin.c
diffstat 24 files changed, 45 insertions(+), 103 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/doveadm-mail-mailbox.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/doveadm/doveadm-mail-mailbox.c	Mon Sep 10 17:19:43 2012 +0300
@@ -421,7 +421,7 @@
 
 	oldbox = mailbox_alloc(oldns->list, oldname, 0);
 	newbox = mailbox_alloc(newns->list, newname, 0);
-	if (mailbox_rename(oldbox, newbox, TRUE) < 0) {
+	if (mailbox_rename(oldbox, newbox) < 0) {
 		i_error("Can't rename mailbox %s to %s: %s", oldname, newname,
 			mailbox_get_last_error(oldbox, NULL));
 		doveadm_mail_failed_mailbox(_ctx, oldbox);
--- a/src/doveadm/dsync/dsync-brain-mailbox-tree-sync.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/doveadm/dsync/dsync-brain-mailbox-tree-sync.c	Mon Sep 10 17:19:43 2012 +0300
@@ -119,7 +119,7 @@
 	case DSYNC_MAILBOX_TREE_SYNC_TYPE_RENAME:
 		destbox = mailbox_alloc(change->ns->list,
 					change->rename_dest_name, 0);
-		ret = mailbox_rename(box, destbox, TRUE);
+		ret = mailbox_rename(box, destbox);
 		func_name = "mailbox_rename";
 		mailbox_free(&destbox);
 		break;
--- a/src/imap/cmd-rename.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/imap/cmd-rename.c	Mon Sep 10 17:19:43 2012 +0300
@@ -37,7 +37,7 @@
 
 	old_box = mailbox_alloc(old_ns->list, oldname, 0);
 	new_box = mailbox_alloc(new_ns->list, newname, 0);
-	if (mailbox_rename(old_box, new_box, TRUE) < 0)
+	if (mailbox_rename(old_box, new_box) < 0)
 		client_send_storage_error(cmd, mailbox_get_storage(old_box));
 	else
 		client_send_tagline(cmd, "OK Rename completed.");
--- a/src/lib-storage/fail-mailbox.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/fail-mailbox.c	Mon Sep 10 17:19:43 2012 +0300
@@ -70,8 +70,7 @@
 }
 
 static int fail_mailbox_rename(struct mailbox *src,
-			       struct mailbox *dest ATTR_UNUSED,
-			       bool rename_children ATTR_UNUSED)
+			       struct mailbox *dest ATTR_UNUSED)
 {
 	mail_storage_set_error(src->storage, MAIL_ERROR_NOTPOSSIBLE,
 			       "Mailbox can't be renamed");
--- a/src/lib-storage/index/imapc/imapc-list.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/index/imapc/imapc-list.c	Mon Sep 10 17:19:43 2012 +0300
@@ -633,20 +633,13 @@
 
 static int
 imapc_list_rename_mailbox(struct mailbox_list *oldlist, const char *oldname,
-			  struct mailbox_list *newlist, const char *newname,
-			  bool rename_children)
+			  struct mailbox_list *newlist, const char *newname)
 {
 	struct imapc_mailbox_list *list = (struct imapc_mailbox_list *)oldlist;
 	struct mailbox_list *fs_list = imapc_list_get_fs(list);
 	struct imapc_command *cmd;
 	struct imapc_simple_context ctx;
 
-	if (!rename_children) {
-		mailbox_list_set_error(oldlist, MAIL_ERROR_NOTPOSSIBLE,
-			"Renaming without children not supported.");
-		return -1;
-	}
-
 	if (oldlist != newlist) {
 		mailbox_list_set_error(oldlist, MAIL_ERROR_NOTPOSSIBLE,
 			"Can't rename mailboxes across storages.");
@@ -660,8 +653,7 @@
 		oldname = imapc_list_get_fs_name(list, oldname);
 		newname = imapc_list_get_fs_name(list, newname);
 		(void)fs_list->v.rename_mailbox(fs_list, oldname,
-						fs_list, newname,
-						rename_children);
+						fs_list, newname);
 	}
 	return ctx.ret;
 }
--- a/src/lib-storage/index/index-storage.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/index/index-storage.c	Mon Sep 10 17:19:43 2012 +0300
@@ -584,14 +584,12 @@
 	return 0;
 }
 
-int index_storage_mailbox_rename(struct mailbox *src, struct mailbox *dest,
-				 bool rename_children)
+int index_storage_mailbox_rename(struct mailbox *src, struct mailbox *dest)
 {
 	guid_128_t guid;
 
 	if (src->list->v.rename_mailbox(src->list, src->name,
-					dest->list, dest->name,
-					rename_children) < 0) {
+					dest->list, dest->name) < 0) {
 		mail_storage_copy_list_error(src->storage, src->list);
 		return -1;
 	}
--- a/src/lib-storage/index/index-storage.h	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/index/index-storage.h	Mon Sep 10 17:19:43 2012 +0300
@@ -75,8 +75,7 @@
 					const struct mailbox_update *update);
 int index_storage_mailbox_delete(struct mailbox *box);
 int index_storage_mailbox_delete_dir(struct mailbox *box, bool mailbox_deleted);
-int index_storage_mailbox_rename(struct mailbox *src, struct mailbox *dest,
-				 bool rename_children);
+int index_storage_mailbox_rename(struct mailbox *src, struct mailbox *dest);
 
 bool index_storage_is_readonly(struct mailbox *box);
 bool index_storage_is_inconsistent(struct mailbox *box);
--- a/src/lib-storage/index/shared/shared-list.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/index/shared/shared-list.c	Mon Sep 10 17:19:43 2012 +0300
@@ -313,8 +313,7 @@
 
 static int
 shared_list_rename_mailbox(struct mailbox_list *oldlist, const char *oldname,
-			   struct mailbox_list *newlist, const char *newname,
-			   bool rename_children)
+			   struct mailbox_list *newlist, const char *newname)
 {
 	struct mail_namespace *ns;
 	int ret;
@@ -323,8 +322,7 @@
 				      newlist, &newname, &ns) < 0)
 		return -1;
 
-	ret = ns->list->v.rename_mailbox(ns->list, oldname, ns->list, newname,
-					 rename_children);
+	ret = ns->list->v.rename_mailbox(ns->list, oldname, ns->list, newname);
 	if (ret < 0)
 		shared_list_copy_error(oldlist, ns);
 	return ret;
--- a/src/lib-storage/list/mailbox-list-fs.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/list/mailbox-list-fs.c	Mon Sep 10 17:19:43 2012 +0300
@@ -482,11 +482,10 @@
 static int fs_list_rename_mailbox(struct mailbox_list *oldlist,
 				  const char *oldname,
 				  struct mailbox_list *newlist,
-				  const char *newname, bool rename_children)
+				  const char *newname)
 {
 	struct mail_storage *oldstorage;
 	const char *oldvname, *oldpath, *newpath, *alt_newpath, *root_path, *p;
-	enum mailbox_list_path_type path_type, alt_path_type;
 	struct stat st;
 	struct mailbox_permissions old_perm, new_perm;
 	bool rmdir_parent = FALSE;
@@ -495,23 +494,12 @@
 	if (mailbox_list_get_storage(&oldlist, oldvname, &oldstorage) < 0)
 		return -1;
 
-	if (rename_children) {
-		path_type = MAILBOX_LIST_PATH_TYPE_DIR;
-		alt_path_type = MAILBOX_LIST_PATH_TYPE_ALT_DIR;
-	} else if (mail_storage_is_mailbox_file(oldstorage) ||
-		   *oldlist->set.maildir_name != '\0') {
-		path_type = MAILBOX_LIST_PATH_TYPE_MAILBOX;
-		alt_path_type = MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX;
-	} else {
-		/* we can't do this, our children would get renamed with us */
-		mailbox_list_set_error(oldlist, MAIL_ERROR_NOTPOSSIBLE,
-			"Can't rename mailbox without its children.");
-		return -1;
-	}
-
-	oldpath = mailbox_list_get_path(oldlist, oldname, path_type);
-	newpath = mailbox_list_get_path(newlist, newname, path_type);
-	alt_newpath = mailbox_list_get_path(newlist, newname, alt_path_type);
+	oldpath = mailbox_list_get_path(oldlist, oldname,
+					MAILBOX_LIST_PATH_TYPE_DIR);
+	newpath = mailbox_list_get_path(newlist, newname,
+					MAILBOX_LIST_PATH_TYPE_DIR);
+	alt_newpath = mailbox_list_get_path(newlist, newname,
+					    MAILBOX_LIST_PATH_TYPE_ALT_DIR);
 
 	root_path = mailbox_list_get_root_path(oldlist, MAILBOX_LIST_PATH_TYPE_MAILBOX);
 	if (strcmp(oldpath, root_path) == 0) {
@@ -597,23 +585,9 @@
 		return -1;
 	}
 
-	if (!rename_children) {
-		/* if there are no child mailboxes, get rid of the mailbox
-		   directory entirely. */
-		oldpath = mailbox_list_get_path(oldlist, oldname,
-						MAILBOX_LIST_PATH_TYPE_DIR);
-		if (rmdir(oldpath) == 0)
-			rmdir_parent = TRUE;
-		else if (errno != ENOENT &&
-			 errno != ENOTEMPTY && errno != EEXIST) {
-			mailbox_list_set_critical(oldlist,
-				"rmdir(%s) failed: %m", oldpath);
-		}
-	}
-
 	if (alt_newpath != NULL) {
 		(void)rename_dir(oldlist, oldname, newlist, newname,
-				 alt_path_type, rmdir_parent);
+				 MAILBOX_LIST_PATH_TYPE_ALT_DIR, rmdir_parent);
 	}
 	(void)rename_dir(oldlist, oldname, newlist, newname,
 			 MAILBOX_LIST_PATH_TYPE_CONTROL, rmdir_parent);
--- a/src/lib-storage/list/mailbox-list-index.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/list/mailbox-list-index.c	Mon Sep 10 17:19:43 2012 +0300
@@ -373,8 +373,7 @@
 mailbox_list_index_rename_mailbox(struct mailbox_list *oldlist,
 				  const char *oldname,
 				  struct mailbox_list *newlist,
-				  const char *newname,
-				  bool rename_children)
+				  const char *newname)
 {
 	struct mailbox_list_index *oldilist = INDEX_LIST_CONTEXT(oldlist);
 
@@ -382,8 +381,7 @@
 	if (oldlist != newlist)
 		mailbox_list_index_refresh_later(newlist);
 	return oldilist->module_ctx.super.
-		rename_mailbox(oldlist, oldname,
-			       newlist, newname, rename_children);
+		rename_mailbox(oldlist, oldname, newlist, newname);
 }
 
 static int
--- a/src/lib-storage/list/mailbox-list-maildir.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/list/mailbox-list-maildir.c	Mon Sep 10 17:19:43 2012 +0300
@@ -555,8 +555,7 @@
 
 static int
 maildir_list_rename_mailbox(struct mailbox_list *oldlist, const char *oldname,
-			    struct mailbox_list *newlist, const char *newname,
-			    bool rename_children)
+			    struct mailbox_list *newlist, const char *newname)
 {
 	const char *oldpath, *newpath, *root_path;
 	int ret;
@@ -606,9 +605,7 @@
 				 MAILBOX_LIST_PATH_TYPE_INDEX);
 
 		found = ret == 0;
-		if (!rename_children)
-			ret = 0;
-		else T_BEGIN {
+		T_BEGIN {
 			ret = maildir_rename_children(oldlist, oldname,
 						      newlist, newname);
 		} T_END;
--- a/src/lib-storage/list/mailbox-list-none.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/list/mailbox-list-none.c	Mon Sep 10 17:19:43 2012 +0300
@@ -119,8 +119,7 @@
 none_list_rename_mailbox(struct mailbox_list *oldlist,
 			 const char *oldname ATTR_UNUSED,
 			 struct mailbox_list *newlist ATTR_UNUSED,
-			 const char *newname ATTR_UNUSED,
-			 bool rename_children ATTR_UNUSED)
+			 const char *newname ATTR_UNUSED)
 {
 	mailbox_list_set_error(oldlist, MAIL_ERROR_NOTPOSSIBLE,
 			       "Not supported");
--- a/src/lib-storage/mail-storage-private.h	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/mail-storage-private.h	Mon Sep 10 17:19:43 2012 +0300
@@ -131,8 +131,7 @@
 		      bool directory);
 	int (*update)(struct mailbox *box, const struct mailbox_update *update);
 	int (*delete)(struct mailbox *box);
-	int (*rename)(struct mailbox *src, struct mailbox *dest,
-		      bool rename_children);
+	int (*rename)(struct mailbox *src, struct mailbox *dest);
 
 	int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
 			  struct mailbox_status *status_r);
--- a/src/lib-storage/mail-storage.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/mail-storage.c	Mon Sep 10 17:19:43 2012 +0300
@@ -1206,8 +1206,7 @@
 	return TRUE;
 }
 
-int mailbox_rename(struct mailbox *src, struct mailbox *dest,
-		   bool rename_children)
+int mailbox_rename(struct mailbox *src, struct mailbox *dest)
 {
 	const char *error = NULL;
 
@@ -1238,7 +1237,7 @@
 		return -1;
 	}
 
-	return src->v.rename(src, dest, rename_children);
+	return src->v.rename(src, dest);
 }
 
 int mailbox_set_subscribed(struct mailbox *box, bool set)
--- a/src/lib-storage/mail-storage.h	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/mail-storage.h	Mon Sep 10 17:19:43 2012 +0300
@@ -439,11 +439,10 @@
 /* Delete mailbox, but only if it's empty. If it's not, fails with
    MAIL_ERROR_EXISTS. */
 int mailbox_delete_empty(struct mailbox *box);
-/* Rename mailbox. Renaming across different mailbox lists is possible only
-   between private namespaces and storages of the same type. If the rename
-   fails, the error is set to src's storage. */
-int mailbox_rename(struct mailbox *src, struct mailbox *dest,
-		   bool rename_children);
+/* Rename mailbox (and its children). Renaming across different mailbox lists
+   is possible only between private namespaces and storages of the same type.
+   If the rename fails, the error is set to src's storage. */
+int mailbox_rename(struct mailbox *src, struct mailbox *dest);
 /* Subscribe/unsubscribe mailbox. Subscribing to
    nonexistent mailboxes is optional. */
 int mailbox_set_subscribed(struct mailbox *box, bool set);
--- a/src/lib-storage/mailbox-list-private.h	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/lib-storage/mailbox-list-private.h	Mon Sep 10 17:19:43 2012 +0300
@@ -86,8 +86,7 @@
 	int (*delete_dir)(struct mailbox_list *list, const char *name);
 	int (*delete_symlink)(struct mailbox_list *list, const char *name);
 	int (*rename_mailbox)(struct mailbox_list *oldlist, const char *oldname,
-			      struct mailbox_list *newlist, const char *newname,
-			      bool rename_children);
+			      struct mailbox_list *newlist, const char *newname);
 
 	int (*notify_init)(struct mailbox_list *list,
 			   enum mailbox_list_notify_event mask,
--- a/src/plugins/acl/acl-mailbox.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/plugins/acl/acl-mailbox.c	Mon Sep 10 17:19:43 2012 +0300
@@ -184,8 +184,7 @@
 }
 
 static int
-acl_mailbox_rename(struct mailbox *src, struct mailbox *dest,
-		   bool rename_children)
+acl_mailbox_rename(struct mailbox *src, struct mailbox *dest)
 {
 	struct acl_mailbox *abox = ACL_CONTEXT(src);
 	int ret;
@@ -217,7 +216,7 @@
 		return -1;
 	}
 
-	return abox->module_ctx.super.rename(src, dest, rename_children);
+	return abox->module_ctx.super.rename(src, dest);
 }
 
 static int
--- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Mon Sep 10 17:19:43 2012 +0300
@@ -231,8 +231,7 @@
 }
 
 static int
-lazy_expunge_mailbox_rename(struct mailbox *src, struct mailbox *dest,
-			    bool rename_children)
+lazy_expunge_mailbox_rename(struct mailbox *src, struct mailbox *dest)
 {
 	union mailbox_module_context *lbox = LAZY_EXPUNGE_CONTEXT(src);
 	struct lazy_expunge_mailbox_list *src_llist =
@@ -247,7 +246,7 @@
 			"Can't rename mailboxes to/from expunge namespace.");
 		return -1;
 	}
-	return lbox->super.rename(src, dest, rename_children);
+	return lbox->super.rename(src, dest);
 }
 
 static void lazy_expunge_mailbox_allocated(struct mailbox *box)
--- a/src/plugins/mail-log/mail-log-plugin.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/plugins/mail-log/mail-log-plugin.c	Mon Sep 10 17:19:43 2012 +0300
@@ -482,8 +482,7 @@
 }
 
 static void
-mail_log_mailbox_rename(struct mailbox *src,
-			struct mailbox *dest, bool rename_children ATTR_UNUSED)
+mail_log_mailbox_rename(struct mailbox *src, struct mailbox *dest)
 {
 	struct mail_log_user *muser = MAIL_LOG_USER_CONTEXT(src->storage->user);
 
--- a/src/plugins/notify/notify-plugin-private.h	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/plugins/notify/notify-plugin-private.h	Mon Sep 10 17:19:43 2012 +0300
@@ -19,8 +19,7 @@
 void notify_contexts_mailbox_delete_begin(struct mailbox *box);
 void notify_contexts_mailbox_delete_commit(struct mailbox *box);
 void notify_contexts_mailbox_delete_rollback(void);
-void notify_contexts_mailbox_rename(struct mailbox *src, struct mailbox *dest,
-				    bool rename_children);
+void notify_contexts_mailbox_rename(struct mailbox *src, struct mailbox *dest);
 void notify_contexts_mailbox_set_subscribed(struct mailbox *box,
 					    bool subscribed);
 
--- a/src/plugins/notify/notify-plugin.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/plugins/notify/notify-plugin.c	Mon Sep 10 17:19:43 2012 +0300
@@ -202,14 +202,13 @@
 	}
 }
 
-void notify_contexts_mailbox_rename(struct mailbox *src, struct mailbox *dest,
-				    bool rename_children)
+void notify_contexts_mailbox_rename(struct mailbox *src, struct mailbox *dest)
 {
 	struct notify_context *ctx;
 
 	for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
 		if (ctx->v.mailbox_rename != NULL)
-			ctx->v.mailbox_rename(src, dest, rename_children);
+			ctx->v.mailbox_rename(src, dest);
 	}
 }
 
--- a/src/plugins/notify/notify-plugin.h	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/plugins/notify/notify-plugin.h	Mon Sep 10 17:19:43 2012 +0300
@@ -28,8 +28,7 @@
 	void *(*mailbox_delete_begin)(struct mailbox *box);
 	void (*mailbox_delete_commit)(void *txn, struct mailbox *box);
 	void (*mailbox_delete_rollback)(void *txn);
-	void (*mailbox_rename)(struct mailbox *src, struct mailbox *dest,
-			       bool rename_children);
+	void (*mailbox_rename)(struct mailbox *src, struct mailbox *dest);
 	void (*mailbox_set_subscribed)(struct mailbox *box, bool subscribed);
 };
 
--- a/src/plugins/notify/notify-storage.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/plugins/notify/notify-storage.c	Mon Sep 10 17:19:43 2012 +0300
@@ -235,15 +235,14 @@
 }
 
 static int
-notify_mailbox_rename(struct mailbox *src, struct mailbox *dest,
-		      bool rename_children)
+notify_mailbox_rename(struct mailbox *src, struct mailbox *dest)
 {
 	union mailbox_module_context *lbox = NOTIFY_CONTEXT(src);
 
-	if (lbox->super.rename(src, dest, rename_children) < 0)
+	if (lbox->super.rename(src, dest) < 0)
 		return -1;
 
-	notify_contexts_mailbox_rename(src, dest, rename_children);
+	notify_contexts_mailbox_rename(src, dest);
 	return 0;
 }
 
--- a/src/plugins/replication/replication-plugin.c	Fri Sep 07 16:43:44 2012 +0300
+++ b/src/plugins/replication/replication-plugin.c	Mon Sep 10 17:19:43 2012 +0300
@@ -273,8 +273,7 @@
 
 static void
 replication_mailbox_rename(struct mailbox *src ATTR_UNUSED,
-			   struct mailbox *dest,
-			   bool rename_children ATTR_UNUSED)
+			   struct mailbox *dest)
 {
 	replication_notify(mailbox_get_namespace(dest),
 			   REPLICATION_PRIORITY_LOW);