Mercurial > dovecot > core-2.2
changeset 22286:25366e8388d9
lib-storage: Add mailbox_list_delete_finish_ret()
This simplifies deletion logic for mailbox list backends.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Tue, 27 Jun 2017 16:36:56 +0300 |
parents | e461d41c1835 |
children | ff11f4d5dbbc |
files | src/lib-storage/list/mailbox-list-delete.c src/lib-storage/list/mailbox-list-delete.h |
diffstat | 2 files changed, 37 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/list/mailbox-list-delete.c Tue Jun 27 16:13:34 2017 +0300 +++ b/src/lib-storage/list/mailbox-list-delete.c Tue Jun 27 16:36:56 2017 +0300 @@ -332,6 +332,34 @@ return ret; } +int mailbox_list_delete_finish_ret(struct mailbox_list *list, + const char *name, bool root_delete_success) +{ + int ret2; + + if (!root_delete_success && + mailbox_list_get_last_mail_error(list) != MAIL_ERROR_NOTFOUND) { + /* unexpected error - preserve it */ + return -1; + } else if ((ret2 = mailbox_list_delete_finish(list, name)) < 0) { + /* unexpected error */ + return -1; + } else if (ret2 > 0) { + /* successfully deleted */ + return 0; + } else if (root_delete_success) { + /* nothing deleted by us, but root was successfully deleted */ + return 0; + } else { + /* nothing deleted by us and the root didn't exist either. + make sure the list has the correct error set, since it + could have been changed. */ + mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND, + T_MAILBOX_LIST_ERR_NOT_FOUND(list, name)); + return -1; + } +} + int mailbox_list_delete_trash(const char *path) { if (unlink_directory(path, UNLINK_DIRECTORY_FLAG_RMDIR) < 0) {
--- a/src/lib-storage/list/mailbox-list-delete.h Tue Jun 27 16:13:34 2017 +0300 +++ b/src/lib-storage/list/mailbox-list-delete.h Tue Jun 27 16:36:56 2017 +0300 @@ -51,6 +51,15 @@ Returns 1 if anything was unlink()ed or rmdir()ed, 0 if not. Returns -1 and sets the list error on any errors. */ int mailbox_list_delete_finish(struct mailbox_list *list, const char *name); +/* Finish mailbox deletion by calling mailbox_list_delete_finish() if needed. + Set root_delete_success to TRUE if the mail root directory was successfully + deleted, FALSE if not. The list is expected to have a proper error when + root_delete_success==FALSE. + + Returns 0 if mailbox deletion should be treated as success. If not, returns + -1 and sets the list error if necessary. */ +int mailbox_list_delete_finish_ret(struct mailbox_list *list, + const char *name, bool root_delete_success); /* rmdir() path and its parent directories until the root directory is reached. The root isn't rmdir()ed. */