Skip to content

Commit

Permalink
lib-storage: clean up mailbox_list_create to improve readability
Browse files Browse the repository at this point in the history
There is no reason to use mailbox_list_driver_find() here instead of
mailbox_list_find_class() as (1) we do not need the index into the list
driver array, and (2) dealing with double-pointers is harder than regular
pointers.
  • Loading branch information
Josef 'Jeff' Sipek authored and GitLab committed Oct 19, 2016
1 parent f948338 commit ac2defe
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/lib-storage/mailbox-list.c
Expand Up @@ -107,37 +107,35 @@ int mailbox_list_create(const char *driver, struct mail_namespace *ns,
enum mailbox_list_flags flags,
struct mailbox_list **list_r, const char **error_r)
{
const struct mailbox_list *const *class_p;
const struct mailbox_list *class;
struct mailbox_list *list;
unsigned int idx;

i_assert(ns->list == NULL ||
(flags & MAILBOX_LIST_FLAG_SECONDARY) != 0);

i_assert(set->subscription_fname == NULL ||
*set->subscription_fname != '\0');

if (!mailbox_list_driver_find(driver, &idx)) {
if ((class = mailbox_list_find_class(driver)) == NULL) {
*error_r = "Unknown driver name";
return -1;
}

class_p = array_idx(&mailbox_list_drivers, idx);
if (((*class_p)->props & MAILBOX_LIST_PROP_NO_MAILDIR_NAME) != 0 &&
if ((class->props & MAILBOX_LIST_PROP_NO_MAILDIR_NAME) != 0 &&
*set->maildir_name != '\0') {
*error_r = "maildir_name not supported by this driver";
return -1;
}
if (((*class_p)->props & MAILBOX_LIST_PROP_NO_ALT_DIR) != 0 &&
if ((class->props & MAILBOX_LIST_PROP_NO_ALT_DIR) != 0 &&
set->alt_dir != NULL) {
*error_r = "alt_dir not supported by this driver";
return -1;
}

i_assert(set->root_dir == NULL || *set->root_dir != '\0' ||
((*class_p)->props & MAILBOX_LIST_PROP_NO_ROOT) != 0);
(class->props & MAILBOX_LIST_PROP_NO_ROOT) != 0);

list = (*class_p)->v.alloc();
list = class->v.alloc();
array_create(&list->module_contexts, list->pool, sizeof(void *), 5);

list->ns = ns;
Expand Down

0 comments on commit ac2defe

Please sign in to comment.