Skip to content

Commit

Permalink
lib-storage: mailbox_list_index_handle_corruption() - Lock mailbox li…
Browse files Browse the repository at this point in the history
…st while rebuilding

This guards against simultaneous mailbox create/delete/rename.
  • Loading branch information
sirainen committed Feb 19, 2018
1 parent 98a0236 commit ccfccd9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/lib-storage/list/mailbox-list-index.c
Expand Up @@ -625,7 +625,19 @@ int mailbox_list_index_handle_corruption(struct mailbox_list *list)
if (ilist->handling_corruption)
return 0;
ilist->handling_corruption = TRUE;
ret = list_handle_corruption_locked(list, reason);

/* Perform the rebuilding locked. Note that if we're here because
INBOX wasn't found, this may be because another process is in the
middle of creating it. Waiting for the lock here makes sure that
we don't start rebuilding before it's finished. In that case the
rebuild is a bit unnecessary, but harmless (and avoiding the rebuild
just adds extra code complexity). */
if (mailbox_list_lock(list) < 0)
ret = -1;
else {
ret = list_handle_corruption_locked(list, reason);
mailbox_list_unlock(list);
}
ilist->handling_corruption = FALSE;
return ret;
}
Expand Down

0 comments on commit ccfccd9

Please sign in to comment.