From: Timo Sirainen Date: Tue, 27 Jun 2017 13:36:56 +0000 (+0300) Subject: lib-storage: Add mailbox_list_delete_finish_ret() X-Git-Tag: 2.3.0.rc1~1348 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=12bd6ddfeb75d81ccc09bf34b374b0637dfe890f;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Add mailbox_list_delete_finish_ret() This simplifies deletion logic for mailbox list backends. --- diff --git a/src/lib-storage/list/mailbox-list-delete.c b/src/lib-storage/list/mailbox-list-delete.c index 5565ebf322..073171f87e 100644 --- a/src/lib-storage/list/mailbox-list-delete.c +++ b/src/lib-storage/list/mailbox-list-delete.c @@ -333,6 +333,34 @@ int mailbox_list_delete_finish(struct mailbox_list *list, const char *name) 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, const char **error_r) { if (unlink_directory(path, UNLINK_DIRECTORY_FLAG_RMDIR, error_r) < 0) { diff --git a/src/lib-storage/list/mailbox-list-delete.h b/src/lib-storage/list/mailbox-list-delete.h index 82588b8754..83952a5473 100644 --- a/src/lib-storage/list/mailbox-list-delete.h +++ b/src/lib-storage/list/mailbox-list-delete.h @@ -51,6 +51,15 @@ int mailbox_list_delete_mailbox_nonrecursive(struct mailbox_list *list, 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. */