Skip to content

Commit

Permalink
lib-storage: Check for storage existence from index dir with ITERINDEX
Browse files Browse the repository at this point in the history
The root path creation doesn't really even seem to be necessary, because any
mailbox access will automatically mkdir the missing directories anyway.
Although writing other files might not work so well, such as
mail_attribute_dict that points inside the mail directory.

This change simply changes the mailboxes/ directory to be looked up from
index directory instead of the mail root directory. It also mkdirs the
index/mailboxes/ directory afterwards if it didn't exist. So practically
this change shouldn't break anything, since the mailboxes/ directory should
always exist for both root and the indexes.
  • Loading branch information
sirainen committed Jul 3, 2017
1 parent cfc2d11 commit a9f112f
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/lib-storage/mail-storage.c
Expand Up @@ -227,8 +227,8 @@ mail_storage_get_class(struct mail_namespace *ns, const char *driver,
}

static int
mail_storage_verify_root(const char *root_dir, bool autocreate,
const char **error_r)
mail_storage_verify_root(const char *root_dir, const char *dir_type,
bool autocreate, const char **error_r)
{
struct stat st;

Expand All @@ -243,7 +243,7 @@ mail_storage_verify_root(const char *root_dir, bool autocreate,
return -1;
} else if (!autocreate) {
*error_r = t_strdup_printf(
"Root mail directory doesn't exist: %s", root_dir);
"Root %s directory doesn't exist: %s", dir_type, root_dir);
return -1;
} else {
/* doesn't exist */
Expand All @@ -255,12 +255,19 @@ static int
mail_storage_create_root(struct mailbox_list *list,
enum mail_storage_flags flags, const char **error_r)
{
const char *root_dir, *error;
const char *root_dir, *type_name, *error;
enum mailbox_list_path_type type;
bool autocreate;
int ret;

if (!mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_MAILBOX,
&root_dir)) {
if (list->set.iter_from_index_dir) {
type = MAILBOX_LIST_PATH_TYPE_INDEX;
type_name = "index";
} else {
type = MAILBOX_LIST_PATH_TYPE_MAILBOX;
type_name = "mail";
}
if (!mailbox_list_get_root_path(list, type, &root_dir)) {
/* storage doesn't use directories (e.g. shared root) */
return 0;
}
Expand All @@ -271,20 +278,32 @@ mail_storage_create_root(struct mailbox_list *list,

/* we don't need to verify, but since debugging is
enabled, check and log if the root doesn't exist */
if (mail_storage_verify_root(root_dir, FALSE, &error) < 0) {
if (mail_storage_verify_root(root_dir, type_name, FALSE, &error) < 0) {
i_debug("Namespace %s: Creating storage despite: %s",
list->ns->prefix, error);
}
return 0;
}

autocreate = (flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) == 0;
ret = mail_storage_verify_root(root_dir, autocreate, error_r);
ret = mail_storage_verify_root(root_dir, type_name, autocreate, error_r);
if (ret == 0) {
ret = mailbox_list_try_mkdir_root(list, root_dir,
const char *mail_root_dir;

if (!list->set.iter_from_index_dir)
mail_root_dir = root_dir;
else if (!mailbox_list_get_root_path(list,
MAILBOX_LIST_PATH_TYPE_MAILBOX, &mail_root_dir))
i_unreached();
ret = mailbox_list_try_mkdir_root(list, mail_root_dir,
MAILBOX_LIST_PATH_TYPE_MAILBOX,
error_r);
}
if (ret == 0 && list->set.iter_from_index_dir) {
ret = mailbox_list_try_mkdir_root(list, root_dir,
MAILBOX_LIST_PATH_TYPE_INDEX,
error_r);
}
return ret < 0 ? -1 : 0;
}

Expand Down

0 comments on commit a9f112f

Please sign in to comment.