Skip to content

Commit

Permalink
lib-storage: Add mailbox_list_delete_finish_ret()
Browse files Browse the repository at this point in the history
This simplifies deletion logic for mailbox list backends.
  • Loading branch information
sirainen authored and GitLab committed Jun 29, 2017
1 parent a1bef9d commit 12bd6dd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/lib-storage/list/mailbox-list-delete.c
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/lib-storage/list/mailbox-list-delete.h
Expand Up @@ -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. */
Expand Down

0 comments on commit 12bd6dd

Please sign in to comment.