]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add mailbox_list_delete_finish_ret()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 27 Jun 2017 13:36:56 +0000 (16:36 +0300)
committerGitLab <gitlab@git.dovecot.net>
Thu, 29 Jun 2017 12:46:49 +0000 (15:46 +0300)
This simplifies deletion logic for mailbox list backends.

src/lib-storage/list/mailbox-list-delete.c
src/lib-storage/list/mailbox-list-delete.h

index 5565ebf322a152f4be6d0255f5b3be63cf3a92c1..073171f87e375d2112ca934968e623bdb4a8f6df 100644 (file)
@@ -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) {
index 82588b8754f2a8b276a62c98b11bf61bb247f73b..83952a54730e8e39b12a550ca6b7867d811b896d 100644 (file)
@@ -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. */