dovecot-2.0: lib-storage: Mailbox renaming API changed.
dovecot at dovecot.org
dovecot at dovecot.org
Sun Feb 14 22:33:02 EET 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/292562f9b12c
changeset: 10711:292562f9b12c
user: Timo Sirainen <tss at iki.fi>
date: Sun Feb 14 22:32:59 2010 +0200
description:
lib-storage: Mailbox renaming API changed.
diffstat:
src/dsync/dsync-worker-local.c | 12 +-
src/imap/cmd-rename.c | 10 +-
src/lib-storage/index/cydir/cydir-storage.c | 1 +
src/lib-storage/index/dbox-common/dbox-storage.c | 111 ------------
src/lib-storage/index/dbox-common/dbox-storage.h | 7 -
src/lib-storage/index/dbox-multi/mdbox-storage.c | 19 +--
src/lib-storage/index/dbox-single/sdbox-storage.c | 19 +--
src/lib-storage/index/index-storage.c | 17 +
src/lib-storage/index/index-storage.h | 2 +
src/lib-storage/index/maildir/maildir-storage.c | 36 +---
src/lib-storage/index/mbox/mbox-storage.c | 1 +
src/lib-storage/index/raw/raw-storage.c | 1 +
src/lib-storage/index/shared/shared-list.c | 25 +--
src/lib-storage/list/mailbox-list-fs.c | 62 +++++-
src/lib-storage/list/mailbox-list-maildir.c | 240 +++++++++++++------------
src/lib-storage/mail-storage-private.h | 2 +
src/lib-storage/mail-storage.c | 41 ++++-
src/lib-storage/mail-storage.h | 5 +
src/lib-storage/mailbox-list-private.h | 5 -
src/lib-storage/mailbox-list.c | 73 +------
src/lib-storage/mailbox-list.h | 11 +-
src/lib-storage/test-mailbox.c | 10 +
src/plugins/lazy-expunge/lazy-expunge-plugin.c | 53 +++--
src/plugins/virtual/virtual-storage.c | 1 +
24 files changed, 323 insertions(+), 441 deletions(-)
diffs (truncated from 1265 to 300 lines):
diff -r 3d7fb69184b3 -r 292562f9b12c src/dsync/dsync-worker-local.c
--- a/src/dsync/dsync-worker-local.c Sun Feb 14 22:30:43 2010 +0200
+++ b/src/dsync/dsync-worker-local.c Sun Feb 14 22:32:59 2010 +0200
@@ -1136,6 +1136,7 @@
(struct local_dsync_worker *)_worker;
struct local_dsync_mailbox *lbox;
struct mailbox_list *list;
+ struct mailbox *old_box, *new_box;
const char *newname;
lbox = hash_table_lookup(worker->mailbox_hash, mailbox);
@@ -1156,14 +1157,19 @@
}
mailbox_list_set_changelog_timestamp(list, dsync_box->last_change);
- if (mailbox_list_rename_mailbox(list, lbox->storage_name,
- list, newname, FALSE) < 0) {
+ old_box = mailbox_alloc(list, lbox->storage_name, 0);
+ new_box = mailbox_alloc(list, newname, 0);
+ if (mailbox_rename(old_box, new_box, FALSE) < 0) {
+ struct mail_storage *storage = mailbox_get_storage(old_box);
+
i_error("Can't rename mailbox %s to %s: %s", lbox->storage_name,
- newname, mailbox_list_get_last_error(list, NULL));
+ newname, mail_storage_get_last_error(storage, NULL));
dsync_worker_set_failure(_worker);
} else {
lbox->storage_name = p_strdup(worker->pool, newname);
}
+ mailbox_free(&old_box);
+ mailbox_free(&new_box);
mailbox_list_set_changelog_timestamp(list, (time_t)-1);
}
diff -r 3d7fb69184b3 -r 292562f9b12c src/imap/cmd-rename.c
--- a/src/imap/cmd-rename.c Sun Feb 14 22:30:43 2010 +0200
+++ b/src/imap/cmd-rename.c Sun Feb 14 22:32:59 2010 +0200
@@ -7,6 +7,7 @@
bool cmd_rename(struct client_command_context *cmd)
{
struct mail_namespace *old_ns, *new_ns;
+ struct mailbox *old_box, *new_box;
const char *oldname, *newname;
unsigned int oldlen;
@@ -37,10 +38,13 @@
}
}
- if (mailbox_list_rename_mailbox(old_ns->list, oldname,
- new_ns->list, newname, TRUE) < 0)
- client_send_list_error(cmd, old_ns->list);
+ 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)
+ client_send_storage_error(cmd, mailbox_get_storage(old_box));
else
client_send_tagline(cmd, "OK Rename completed.");
+ mailbox_free(&old_box);
+ mailbox_free(&new_box);
return TRUE;
}
diff -r 3d7fb69184b3 -r 292562f9b12c src/lib-storage/index/cydir/cydir-storage.c
--- a/src/lib-storage/index/cydir/cydir-storage.c Sun Feb 14 22:30:43 2010 +0200
+++ b/src/lib-storage/index/cydir/cydir-storage.c Sun Feb 14 22:32:59 2010 +0200
@@ -203,6 +203,7 @@
cydir_mailbox_create,
index_storage_mailbox_update,
index_storage_mailbox_delete,
+ index_storage_mailbox_rename,
index_storage_get_status,
NULL,
NULL,
diff -r 3d7fb69184b3 -r 292562f9b12c src/lib-storage/index/dbox-common/dbox-storage.c
--- a/src/lib-storage/index/dbox-common/dbox-storage.c Sun Feb 14 22:30:43 2010 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-storage.c Sun Feb 14 22:32:59 2010 +0200
@@ -124,26 +124,6 @@
}
}
-static const char *
-dbox_get_alt_path(struct mailbox_list *list, const char *path)
-{
- struct mail_storage *storage = list->ns->storage;
- const char *root;
- unsigned int len;
-
- if (list->set.alt_dir == NULL ||
- (storage->class_flags & MAIL_STORAGE_CLASS_FLAG_UNIQUE_ROOT) != 0)
- return NULL;
-
- root = mailbox_list_get_path(list, NULL, MAILBOX_LIST_PATH_TYPE_DIR);
- len = strlen(root);
- if (strncmp(path, root, len) != 0 && path[len] == '/') {
- /* can't determine the alt path - shouldn't happen */
- return NULL;
- }
- return t_strconcat(list->set.alt_dir, path + len, NULL);
-}
-
int dbox_mailbox_create(struct mailbox *box,
const struct mailbox_update *update, bool directory)
{
@@ -226,94 +206,3 @@
}
return ret;
}
-
-static int
-dbox_list_rename_get_alt_paths(struct mailbox_list *oldlist,
- const char *oldname,
- struct mailbox_list *newlist,
- const char *newname,
- enum mailbox_list_path_type path_type,
- const char **oldpath_r, const char **newpath_r)
-{
- const char *path;
-
- path = mailbox_list_get_path(oldlist, oldname, path_type);
- *oldpath_r = dbox_get_alt_path(oldlist, path);
- if (*oldpath_r == NULL)
- return 0;
-
- path = mailbox_list_get_path(newlist, newname, path_type);
- *newpath_r = dbox_get_alt_path(newlist, path);
- if (*newpath_r == NULL) {
- /* destination dbox storage doesn't have alt-path defined.
- we can't do the rename easily. */
- mailbox_list_set_error(oldlist, MAIL_ERROR_NOTPOSSIBLE,
- "Can't rename mailboxes across specified storages.");
- return -1;
- }
- return 1;
-}
-
-int dbox_list_rename_mailbox_pre(struct mailbox_list *oldlist,
- const char *oldname,
- struct mailbox_list *newlist,
- const char *newname)
-{
- const char *alt_oldpath, *alt_newpath;
- struct stat st;
- int ret;
-
- ret = dbox_list_rename_get_alt_paths(oldlist, oldname, newlist, newname,
- MAILBOX_LIST_PATH_TYPE_DIR,
- &alt_oldpath, &alt_newpath);
- if (ret <= 0)
- return ret;
-
- if (stat(alt_newpath, &st) == 0) {
- /* race condition or a directory left there lying around?
- safest to just report error. */
- mailbox_list_set_error(oldlist, MAIL_ERROR_EXISTS,
- "Target mailbox already exists");
- return -1;
- } else if (errno != ENOENT) {
- mailbox_list_set_critical(oldlist, "stat(%s) failed: %m",
- alt_newpath);
- return -1;
- }
- return 0;
-}
-
-int dbox_list_rename_mailbox(struct mailbox_list *oldlist, const char *oldname,
- struct mailbox_list *newlist, const char *newname,
- bool rename_children)
-{
- enum mailbox_list_path_type path_type;
- const char *alt_oldpath, *alt_newpath, *path;
- int ret;
-
- path_type = rename_children ? MAILBOX_LIST_PATH_TYPE_DIR :
- MAILBOX_LIST_PATH_TYPE_MAILBOX;
- ret = dbox_list_rename_get_alt_paths(oldlist, oldname, newlist, newname,
- path_type, &alt_oldpath,
- &alt_newpath);
- if (ret <= 0)
- return ret;
-
- if (rename(alt_oldpath, alt_newpath) == 0) {
- /* ok */
- if (!rename_children) {
- path = mailbox_list_get_path(oldlist, oldname,
- MAILBOX_LIST_PATH_TYPE_DIR);
- if (rmdir(path) < 0 &&
- errno != ENOENT && errno != ENOTEMPTY) {
- mailbox_list_set_critical(oldlist,
- "rmdir(%s) failed: %m", path);
- }
- }
- } else if (errno != ENOENT) {
- /* renaming is done already, so just log the error */
- mailbox_list_set_critical(oldlist, "rename(%s, %s) failed: %m",
- alt_oldpath, alt_newpath);
- }
- return 0;
-}
diff -r 3d7fb69184b3 -r 292562f9b12c src/lib-storage/index/dbox-common/dbox-storage.h
--- a/src/lib-storage/index/dbox-common/dbox-storage.h Sun Feb 14 22:30:43 2010 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-storage.h Sun Feb 14 22:32:59 2010 +0200
@@ -54,12 +54,5 @@
const char *mailbox_name,
enum mailbox_list_file_type type,
enum mailbox_info_flags *flags);
-int dbox_list_rename_mailbox_pre(struct mailbox_list *oldlist,
- const char *oldname,
- struct mailbox_list *newlist,
- const char *newname);
-int dbox_list_rename_mailbox(struct mailbox_list *oldlist, const char *oldname,
- struct mailbox_list *newlist, const char *newname,
- bool rename_children);
#endif
diff -r 3d7fb69184b3 -r 292562f9b12c src/lib-storage/index/dbox-multi/mdbox-storage.c
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c Sun Feb 14 22:30:43 2010 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c Sun Feb 14 22:32:59 2010 +0200
@@ -313,21 +313,6 @@
return index_storage_mailbox_delete(box);
}
-static int
-mdbox_list_rename_mailbox(struct mailbox_list *oldlist, const char *oldname,
- struct mailbox_list *newlist, const char *newname,
- bool rename_children)
-{
- struct mdbox_mailbox_list *oldmlist = MDBOX_LIST_CONTEXT(oldlist);
-
- if (oldmlist->module_ctx.super.
- rename_mailbox(oldlist, oldname, newlist, newname,
- rename_children) < 0)
- return -1;
- return dbox_list_rename_mailbox(oldlist, oldname, newlist, newname,
- rename_children);
-}
-
static void dbox_storage_add_list(struct mail_storage *storage ATTR_UNUSED,
struct mailbox_list *list)
{
@@ -335,10 +320,7 @@
mlist = p_new(list->pool, struct mdbox_mailbox_list, 1);
mlist->module_ctx.super = list->v;
-
list->v.iter_is_mailbox = dbox_list_iter_is_mailbox;
- list->v.rename_mailbox = mdbox_list_rename_mailbox;
- list->v.rename_mailbox_pre = dbox_list_rename_mailbox_pre;
MODULE_CONTEXT_SET(list, mdbox_mailbox_list_module, mlist);
}
@@ -370,6 +352,7 @@
dbox_mailbox_create,
mdbox_mailbox_update,
mdbox_mailbox_delete,
+ index_storage_mailbox_rename,
index_storage_get_status,
mdbox_mailbox_get_guid,
NULL,
diff -r 3d7fb69184b3 -r 292562f9b12c src/lib-storage/index/dbox-single/sdbox-storage.c
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c Sun Feb 14 22:30:43 2010 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.c Sun Feb 14 22:32:59 2010 +0200
@@ -203,21 +203,6 @@
return sdbox_write_index_header(box, update);
}
-static int
-sdbox_list_rename_mailbox(struct mailbox_list *oldlist, const char *oldname,
- struct mailbox_list *newlist, const char *newname,
- bool rename_children)
-{
- struct sdbox_mailbox_list *oldmlist = SDBOX_LIST_CONTEXT(oldlist);
-
- if (oldmlist->module_ctx.super.
- rename_mailbox(oldlist, oldname, newlist, newname,
- rename_children) < 0)
- return -1;
- return dbox_list_rename_mailbox(oldlist, oldname, newlist, newname,
- rename_children);
-}
-
static void sdbox_storage_add_list(struct mail_storage *storage ATTR_UNUSED,
struct mailbox_list *list)
{
@@ -225,10 +210,7 @@
mlist = p_new(list->pool, struct sdbox_mailbox_list, 1);
mlist->module_ctx.super = list->v;
-
list->v.iter_is_mailbox = dbox_list_iter_is_mailbox;
- list->v.rename_mailbox = sdbox_list_rename_mailbox;
- list->v.rename_mailbox_pre = dbox_list_rename_mailbox_pre;
MODULE_CONTEXT_SET(list, sdbox_mailbox_list_module, mlist);
}
@@ -260,6 +242,7 @@
dbox_mailbox_create,
dbox_mailbox_update,
index_storage_mailbox_delete,
+ index_storage_mailbox_rename,
index_storage_get_status,
More information about the dovecot-cvs
mailing list