dovecot: mail_storage.create() now returns error message string....
dovecot at dovecot.org
dovecot at dovecot.org
Sun Jul 15 15:30:04 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/56879cc53cec
changeset: 6023:56879cc53cec
user: Timo Sirainen <tss at iki.fi>
date: Sun Jul 15 15:30:00 2007 +0300
description:
mail_storage.create() now returns error message string. Also fixed handling
"/" and empty root paths.
diffstat:
11 files changed, 135 insertions(+), 92 deletions(-)
src/deliver/deliver.c | 6 +--
src/lib-storage/index/cydir/cydir-storage.c | 36 ++++++++++--------
src/lib-storage/index/dbox/dbox-storage.c | 35 ++++++++++-------
src/lib-storage/index/maildir/maildir-storage.c | 25 +++++++-----
src/lib-storage/index/mbox/mbox-storage.c | 46 +++++++++++++----------
src/lib-storage/mail-namespace.c | 27 +++++--------
src/lib-storage/mail-storage-private.h | 3 +
src/lib-storage/mail-storage.c | 33 ++++++++++++++--
src/lib-storage/mail-storage.h | 3 +
src/lib-storage/mailbox-list.c | 3 +
src/plugins/convert/convert-storage.c | 10 ++---
diffs (truncated from 626 to 300 lines):
diff -r 8da2881df0dc -r 56879cc53cec src/deliver/deliver.c
--- a/src/deliver/deliver.c Sun Jul 15 15:27:58 2007 +0300
+++ b/src/deliver/deliver.c Sun Jul 15 15:30:00 2007 +0300
@@ -555,7 +555,7 @@ int main(int argc, char *argv[])
const char *envelope_sender = DEFAULT_ENVELOPE_SENDER;
const char *mailbox = "INBOX";
const char *auth_socket;
- const char *home, *destination, *user, *value;
+ const char *home, *destination, *user, *value, *error;
struct mail_namespace *ns, *mbox_ns;
struct mail_storage *storage;
struct mailbox *box;
@@ -738,8 +738,8 @@ int main(int argc, char *argv[])
mbox_ns = mail_namespaces_init_empty(namespace_pool);
if (mail_storage_create(mbox_ns, "mbox", "/tmp", destination,
- 0, FILE_LOCK_METHOD_FCNTL) < 0)
- i_fatal("Couldn't create internal mbox storage");
+ 0, FILE_LOCK_METHOD_FCNTL, &error) < 0)
+ i_fatal("Couldn't create internal mbox storage: %s", error);
input = create_mbox_stream(0, envelope_sender);
box = mailbox_open(mbox_ns->storage, "Dovecot Delivery Mail", input,
MAILBOX_OPEN_NO_INDEX_FILES |
diff -r 8da2881df0dc -r 56879cc53cec src/lib-storage/index/cydir/cydir-storage.c
--- a/src/lib-storage/index/cydir/cydir-storage.c Sun Jul 15 15:27:58 2007 +0300
+++ b/src/lib-storage/index/cydir/cydir-storage.c Sun Jul 15 15:30:00 2007 +0300
@@ -37,7 +37,8 @@ static int cydir_list_iter_is_mailbox(st
static int
cydir_get_list_settings(struct mailbox_list_settings *list_set,
- const char *data, enum mail_storage_flags flags)
+ const char *data, enum mail_storage_flags flags,
+ const char **error_r)
{
bool debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
const char *p;
@@ -47,10 +48,11 @@ cydir_get_list_settings(struct mailbox_l
list_set->subscription_fname = CYDIR_SUBSCRIPTION_FILE_NAME;
list_set->maildir_name = "";
- if (data == NULL || *data == '\0') {
+ if (data == NULL || *data == '\0' || *data == ':') {
/* we won't do any guessing for this format. */
if (debug)
i_info("cydir: mailbox location not given");
+ *error_r = "Root mail directory not given";
return -1;
}
@@ -73,7 +75,7 @@ cydir_get_list_settings(struct mailbox_l
/* strip trailing '/' */
len = strlen(list_set->root_dir);
- if (list_set->root_dir[len-1] == '/')
+ if (len > 1 && list_set->root_dir[len-1] == '/')
list_set->root_dir = t_strndup(list_set->root_dir, len-1);
if (list_set->index_dir != NULL &&
@@ -95,14 +97,15 @@ static struct mail_storage *cydir_alloc(
return &storage->storage;
}
-static int cydir_create(struct mail_storage *_storage, const char *data)
+static int cydir_create(struct mail_storage *_storage, const char *data,
+ const char **error_r)
{
struct cydir_storage *storage = (struct cydir_storage *)_storage;
struct mailbox_list_settings list_set;
- const char *error;
- struct stat st;
-
- if (cydir_get_list_settings(&list_set, data, _storage->flags) < 0)
+ struct stat st;
+
+ if (cydir_get_list_settings(&list_set, data, _storage->flags,
+ error_r) < 0)
return -1;
list_set.mail_storage_flags = &_storage->flags;
list_set.lock_method = &_storage->lock_method;
@@ -110,7 +113,12 @@ static int cydir_create(struct mail_stor
if ((_storage->flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) {
if (stat(list_set.root_dir, &st) < 0) {
if (errno != ENOENT) {
- i_error("stat(%s) failed: %m",
+ *error_r = t_strdup_printf(
+ "stat(%s) failed: %m",
+ list_set.root_dir);
+ } else {
+ *error_r = t_strdup_printf(
+ "Root mail directory doesn't exist: %s",
list_set.root_dir);
}
return -1;
@@ -118,18 +126,16 @@ static int cydir_create(struct mail_stor
} else {
if (mkdir_parents(list_set.root_dir, CREATE_MODE) < 0 &&
errno != EEXIST) {
- i_error("mkdir_parents(%s) failed: %m",
- list_set.root_dir);
+ *error_r = t_strdup_printf("mkdir(%s) failed: %m",
+ list_set.root_dir);
return -1;
}
}
if (mailbox_list_init(_storage->ns, "fs", &list_set,
mail_storage_get_list_flags(_storage->flags),
- &_storage->list, &error) < 0) {
- i_error("cydir fs: %s", error);
- return -1;
- }
+ &_storage->list, error_r) < 0)
+ return -1;
storage->list_module_ctx.super = _storage->list->v;
_storage->list->v.iter_is_mailbox = cydir_list_iter_is_mailbox;
_storage->list->v.delete_mailbox = cydir_list_delete_mailbox;
diff -r 8da2881df0dc -r 56879cc53cec src/lib-storage/index/dbox/dbox-storage.c
--- a/src/lib-storage/index/dbox/dbox-storage.c Sun Jul 15 15:27:58 2007 +0300
+++ b/src/lib-storage/index/dbox/dbox-storage.c Sun Jul 15 15:30:00 2007 +0300
@@ -117,7 +117,8 @@ dbox_storage_is_valid_create_name(struct
static int
dbox_get_list_settings(struct mailbox_list_settings *list_set,
- const char *data, enum mail_storage_flags flags)
+ const char *data, enum mail_storage_flags flags,
+ const char **error_r)
{
bool debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
const char *p;
@@ -127,10 +128,11 @@ dbox_get_list_settings(struct mailbox_li
list_set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME;
list_set->maildir_name = DBOX_MAILDIR_NAME;
- if (data == NULL || *data == '\0') {
+ if (data == NULL || *data == '\0' || *data == ':') {
/* we won't do any guessing for this format. */
if (debug)
i_info("dbox: mailbox location not given");
+ *error_r = "Root mail directory not given";
return -1;
}
@@ -175,15 +177,16 @@ static struct mail_storage *dbox_alloc(v
return &storage->storage;
}
-static int dbox_create(struct mail_storage *_storage, const char *data)
+static int dbox_create(struct mail_storage *_storage, const char *data,
+ const char **error_r)
{
struct dbox_storage *storage = (struct dbox_storage *)_storage;
struct mailbox_list_settings list_set;
struct mailbox_list *list;
- const char *error;
- struct stat st;
-
- if (dbox_get_list_settings(&list_set, data, _storage->flags) < 0)
+ struct stat st;
+
+ if (dbox_get_list_settings(&list_set, data, _storage->flags,
+ error_r) < 0)
return -1;
list_set.mail_storage_flags = &_storage->flags;
list_set.lock_method = &_storage->lock_method;
@@ -191,7 +194,12 @@ static int dbox_create(struct mail_stora
if ((_storage->flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) {
if (stat(list_set.root_dir, &st) < 0) {
if (errno != ENOENT) {
- i_error("stat(%s) failed: %m",
+ *error_r = t_strdup_printf(
+ "stat(%s) failed: %m",
+ list_set.root_dir);
+ } else {
+ *error_r = t_strdup_printf(
+ "Root mail directory doesn't exist: %s",
list_set.root_dir);
}
return -1;
@@ -199,18 +207,17 @@ static int dbox_create(struct mail_stora
} else {
if (mkdir_parents(list_set.root_dir, CREATE_MODE) < 0 &&
errno != EEXIST) {
- i_error("mkdir_parents(%s) failed: %m",
- list_set.root_dir);
+ *error_r = t_strdup_printf("mkdir(%s) failed: %m",
+ list_set.root_dir);
return -1;
}
}
if (mailbox_list_init(_storage->ns, "fs", &list_set,
mail_storage_get_list_flags(_storage->flags),
- &list, &error) < 0) {
- i_error("dbox fs: %s", error);
- return -1;
- }
+ &list, error_r) < 0)
+ return -1;
+
_storage->list = list;
storage->list_module_ctx.super = list->v;
list->v.is_valid_existing_name = dbox_storage_is_valid_existing_name;
diff -r 8da2881df0dc -r 56879cc53cec src/lib-storage/index/maildir/maildir-storage.c
--- a/src/lib-storage/index/maildir/maildir-storage.c Sun Jul 15 15:27:58 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.c Sun Jul 15 15:30:00 2007 +0300
@@ -62,7 +62,7 @@ static const char *strip_tail_slash(cons
{
size_t len = strlen(path);
- if (len > 0 && path[len-1] == '/')
+ if (len > 1 && path[len-1] == '/')
return t_strndup(path, len-1);
else
return path;
@@ -76,7 +76,7 @@ static int
static int
maildir_get_list_settings(struct mailbox_list_settings *list_set,
const char *data, enum mail_storage_flags flags,
- const char **layout_r)
+ const char **layout_r, const char **error_r)
{
bool debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
const char *home, *path, *p;
@@ -89,7 +89,7 @@ maildir_get_list_settings(struct mailbox
if (data == NULL || *data == '\0') {
if ((flags & MAIL_STORAGE_FLAG_NO_AUTODETECTION) != 0) {
- i_error("maildir: root directory not given");
+ *error_r = "Root mail directory not given";
return -1;
}
@@ -149,9 +149,10 @@ maildir_get_list_settings(struct mailbox
}
}
- if (list_set->root_dir == NULL) {
+ if (list_set->root_dir == NULL || *list_set->root_dir == '\0') {
if (debug)
i_info("maildir: couldn't find root dir");
+ *error_r = "Root mail directory not given";
return -1;
}
list_set->root_dir = strip_tail_slash(list_set->root_dir);
@@ -223,16 +224,18 @@ static struct mail_storage *maildir_allo
}
static int
-maildir_create(struct mail_storage *_storage, const char *data)
+maildir_create(struct mail_storage *_storage, const char *data,
+ const char **error_r)
{
struct maildir_storage *storage = (struct maildir_storage *)_storage;
enum mail_storage_flags flags = _storage->flags;
struct mailbox_list_settings list_set;
struct mailbox_list *list;
- const char *layout, *error;
+ const char *layout;
struct stat st;
- if (maildir_get_list_settings(&list_set, data, flags, &layout) < 0)
+ if (maildir_get_list_settings(&list_set, data, flags, &layout,
+ error_r) < 0)
return -1;
list_set.mail_storage_flags = &_storage->flags;
list_set.lock_method = &_storage->lock_method;
@@ -244,16 +247,16 @@ maildir_create(struct mail_storage *_sto
i_error("stat(%s) failed: %m",
list_set.root_dir);
}
+ *error_r = "Mail storage doesn't exist";
return -1;
}
}
if (mailbox_list_init(_storage->ns, layout, &list_set,
mail_storage_get_list_flags(flags),
- &list, &error) < 0) {
- i_error("maildir %s: %s", layout, error);
- return -1;
- }
+ &list, error_r) < 0)
+ return -1;
+
_storage->list = list;
storage->list_module_ctx.super = list->v;
if (strcmp(layout, MAILDIR_PLUSPLUS_DRIVER_NAME) == 0) {
diff -r 8da2881df0dc -r 56879cc53cec src/lib-storage/index/mbox/mbox-storage.c
--- a/src/lib-storage/index/mbox/mbox-storage.c Sun Jul 15 15:27:58 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c Sun Jul 15 15:30:00 2007 +0300
@@ -253,20 +253,20 @@ get_inbox_file(const char *root_dir, boo
return path;
}
-static const char *create_root_dir(bool debug)
+static const char *create_root_dir(bool debug, const char **error_r)
{
const char *home, *path;
home = getenv("HOME");
More information about the dovecot-cvs
mailing list