Mercurial > dovecot > core-2.2
changeset 11709:737ee10e8104 HEAD
mbox: Support deleting a directory if it contains an empty .imap/ directory.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 02 Jul 2010 15:52:06 +0100 |
parents | d52e9033c3bf |
children | 4cec50afed94 |
files | src/lib-storage/list/mailbox-list-fs.c |
diffstat | 1 files changed, 32 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/list/mailbox-list-fs.c Fri Jul 02 15:23:32 2010 +0100 +++ b/src/lib-storage/list/mailbox-list-fs.c Fri Jul 02 15:52:06 2010 +0100 @@ -410,23 +410,48 @@ return 0; } +static int fs_list_rmdir(struct mailbox_list *list, const char *name, + const char *path) +{ + uint8_t dir_sha128[MAIL_GUID_128_SIZE]; + + if (rmdir(path) < 0) + return -1; + + mailbox_name_get_sha128(name, dir_sha128); + mailbox_list_add_change(list, MAILBOX_LOG_RECORD_DELETE_DIR, + dir_sha128); + return 0; +} + static int fs_list_delete_dir(struct mailbox_list *list, const char *name) { - const char *path; - uint8_t dir_sha128[MAIL_GUID_128_SIZE]; + const char *path, *child_name, *child_path, *p; path = mailbox_list_get_path(list, name, MAILBOX_LIST_PATH_TYPE_DIR); - if (rmdir(path) == 0) { - mailbox_name_get_sha128(name, dir_sha128); - mailbox_list_add_change(list, MAILBOX_LOG_RECORD_DELETE_DIR, - dir_sha128); + if (fs_list_rmdir(list, name, path) == 0) return 0; - } if (errno == ENOENT) { mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND, T_MAIL_ERR_MAILBOX_NOT_FOUND(name)); } else if (errno == ENOTEMPTY) { + /* mbox workaround: if only .imap/ directory is preventing the + deletion, remove it */ + child_name = t_strdup_printf("%s%cchild", name, + list->ns->real_sep); + child_path = mailbox_list_get_path(list, child_name, + MAILBOX_LIST_PATH_TYPE_INDEX); + if (strncmp(path, child_path, strlen(path)) == 0) { + /* drop the "/child" part out. */ + p = strrchr(child_path, '/'); + if (rmdir(t_strdup_until(child_path, p)) == 0) { + /* try again */ + if (fs_list_rmdir(list, name, path) == 0) + return 0; + } + } + mailbox_list_set_error(list, MAIL_ERROR_EXISTS, "Mailbox has children, delete them first"); } else {