dovecot-2.0: lib-storage: Moved mailbox directory creation code ...
dovecot at dovecot.org
dovecot at dovecot.org
Sun Feb 7 01:50:54 EET 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/5fe70b5da1b8
changeset: 10653:5fe70b5da1b8
user: Timo Sirainen <tss at iki.fi>
date: Sun Feb 07 01:50:49 2010 +0200
description:
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
diffstat:
14 files changed, 419 insertions(+), 307 deletions(-)
src/lib-storage/index/cydir/cydir-storage.c | 42 -----
src/lib-storage/index/dbox-common/dbox-storage.c | 53 +------
src/lib-storage/index/index-storage.c | 19 --
src/lib-storage/index/maildir/maildir-storage.c | 161 +++++-----------------
src/lib-storage/index/mbox/mbox-storage.c | 81 ++---------
src/lib-storage/index/shared/shared-list.c | 18 ++
src/lib-storage/list/mailbox-list-fs.c | 97 +++++++++++--
src/lib-storage/list/mailbox-list-maildir.c | 116 +++++++++++++++
src/lib-storage/mail-storage-private.h | 5
src/lib-storage/mail-storage.c | 83 +++++++++++
src/lib-storage/mailbox-list-private.h | 2
src/lib-storage/mailbox-list.h | 6
src/plugins/acl/acl-mailbox-list.c | 25 +++
src/plugins/acl/acl-mailbox.c | 18 --
diffs (truncated from 1134 to 300 lines):
diff -r bdb1ea37ccee -r 5fe70b5da1b8 src/lib-storage/index/cydir/cydir-storage.c
--- a/src/lib-storage/index/cydir/cydir-storage.c Sat Feb 06 23:41:33 2010 +0200
+++ b/src/lib-storage/index/cydir/cydir-storage.c Sun Feb 07 01:50:49 2010 +0200
@@ -48,25 +48,6 @@ cydir_storage_get_list_settings(const st
set->subscription_fname = CYDIR_SUBSCRIPTION_FILE_NAME;
}
-static int create_cydir(struct mail_storage *storage, struct mailbox_list *list,
- const char *path)
-{
- const char *origin;
- mode_t mode;
- gid_t gid;
-
- mailbox_list_get_dir_permissions(list, NULL, &mode, &gid, &origin);
- if (mkdir_parents_chgrp(path, mode, gid, origin) < 0 &&
- errno != EEXIST) {
- if (!mail_storage_set_error_from_errno(storage)) {
- mail_storage_set_critical(storage,
- "mkdir(%s) failed: %m", path);
- }
- return -1;
- }
- return 0;
-}
-
static struct mailbox *
cydir_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
const char *name, struct istream *input,
@@ -114,7 +95,8 @@ static int cydir_mailbox_open(struct mai
/* exists, open it */
} else if (errno == ENOENT && strcmp(box->name, "INBOX") == 0) {
/* INBOX always exists, create it */
- if (create_cydir(box->storage, box->list, box->path) < 0)
+ if (box->list->v.create_mailbox_dir(box->list,
+ box->name, FALSE) < 0)
return -1;
} else if (errno == ENOENT) {
mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
@@ -136,21 +118,11 @@ cydir_mailbox_create(struct mailbox *box
cydir_mailbox_create(struct mailbox *box, const struct mailbox_update *update,
bool directory)
{
- const char *path;
- struct stat st;
-
- path = mailbox_list_get_path(box->list, box->name,
- MAILBOX_LIST_PATH_TYPE_MAILBOX);
- if (stat(path, &st) == 0) {
- mail_storage_set_error(box->storage, MAIL_ERROR_EXISTS,
- "Mailbox already exists");
- return -1;
- }
-
- if (create_cydir(box->storage, box->list, path) < 0)
- return -1;
-
- return directory || update == NULL ? 0 :
+ if (directory &&
+ (box->list->props & MAILBOX_LIST_PROP_NO_NOSELECT) == 0)
+ return 0;
+
+ return update == NULL ? 0 :
index_storage_mailbox_update(box, update);
}
diff -r bdb1ea37ccee -r 5fe70b5da1b8 src/lib-storage/index/dbox-common/dbox-storage.c
--- a/src/lib-storage/index/dbox-common/dbox-storage.c Sat Feb 06 23:41:33 2010 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-storage.c Sun Feb 07 01:50:49 2010 +0200
@@ -157,48 +157,17 @@ int dbox_mailbox_create(struct mailbox *
int dbox_mailbox_create(struct mailbox *box,
const struct mailbox_update *update, bool directory)
{
- const char *path, *alt_path, *origin;
- struct stat st;
-
- path = mailbox_list_get_path(box->list, box->name,
- directory ? MAILBOX_LIST_PATH_TYPE_DIR :
- MAILBOX_LIST_PATH_TYPE_MAILBOX);
- if (stat(path, &st) == 0) {
- mail_storage_set_error(box->storage, MAIL_ERROR_EXISTS,
- "Mailbox already exists");
- return -1;
- }
-
- if (directory) {
- mode_t mode;
- gid_t gid;
-
- mailbox_list_get_dir_permissions(box->list, NULL, &mode,
- &gid, &origin);
- if (mkdir_parents_chgrp(path, mode, gid, origin) == 0)
- return 0;
- else if (errno == EEXIST) {
- mail_storage_set_error(box->storage, MAIL_ERROR_EXISTS,
- "Mailbox already exists");
- } else if (!mail_storage_set_error_from_errno(box->storage)) {
- mail_storage_set_critical(box->storage,
- "mkdir(%s) failed: %m", path);
- }
- return -1;
- }
-
- /* make sure the alt path doesn't exist yet. it shouldn't (except with
- race conditions with RENAME/DELETE), but if something crashed and
- left it lying around we don't want to start overwriting files in
- it. */
- alt_path = dbox_get_alt_path(box->list, path);
- if (alt_path != NULL && stat(alt_path, &st) == 0) {
- mail_storage_set_error(box->storage, MAIL_ERROR_EXISTS,
- "Mailbox already exists");
- return -1;
- }
-
- return dbox_mailbox_create_indexes(box, update);
+ struct dbox_storage *storage = (struct dbox_storage *)box->storage;
+
+ if (directory &&
+ (box->list->props & MAILBOX_LIST_PROP_NO_NOSELECT) == 0)
+ return 0;
+
+ if (index_storage_mailbox_open(box) < 0)
+ return -1;
+ if (storage->v.mailbox_create_indexes(box, update) < 0)
+ return -1;
+ return 0;
}
int dbox_list_iter_is_mailbox(struct mailbox_list_iterate_context *ctx ATTR_UNUSED,
diff -r bdb1ea37ccee -r 5fe70b5da1b8 src/lib-storage/index/index-storage.c
--- a/src/lib-storage/index/index-storage.c Sat Feb 06 23:41:33 2010 +0200
+++ b/src/lib-storage/index/index-storage.c Sun Feb 07 01:50:49 2010 +0200
@@ -451,8 +451,6 @@ void index_storage_mailbox_alloc(struct
{
struct mailbox *box = &ibox->box;
const char *path;
- gid_t dir_gid;
- const char *origin, *dir_origin;
string_t *vname;
if (name != NULL) {
@@ -487,18 +485,11 @@ void index_storage_mailbox_alloc(struct
ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL;
ibox->index = index_storage_alloc(box->list, name, flags, index_prefix);
- if (box->file_create_mode == 0) {
- mailbox_list_get_permissions(box->list, name,
- &box->file_create_mode,
- &box->file_create_gid, &origin);
- box->file_create_gid_origin = p_strdup(box->pool, origin);
- mailbox_list_get_dir_permissions(box->list, name,
- &box->dir_create_mode,
- &dir_gid, &dir_origin);
- mail_index_set_permissions(ibox->index,
- box->file_create_mode,
- box->file_create_gid, origin);
- }
+ if (box->file_create_mode == 0)
+ mailbox_refresh_permissions(box);
+ mail_index_set_permissions(ibox->index, box->file_create_mode,
+ box->file_create_gid,
+ box->file_create_gid_origin);
}
int index_storage_mailbox_enable(struct mailbox *box,
diff -r bdb1ea37ccee -r 5fe70b5da1b8 src/lib-storage/index/maildir/maildir-storage.c
--- a/src/lib-storage/index/maildir/maildir-storage.c Sat Feb 06 23:41:33 2010 +0200
+++ b/src/lib-storage/index/maildir/maildir-storage.c Sun Feb 07 01:50:49 2010 +0200
@@ -22,8 +22,6 @@
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
-
-#define MAILDIR_SUBFOLDER_FILENAME "maildirfolder"
#define MAILDIR_LIST_CONTEXT(obj) \
MODULE_CONTEXT(obj, maildir_mailbox_list_module)
@@ -293,19 +291,16 @@ static int maildir_check_tmp(struct mail
}
/* create or fix maildir, ignore if it already exists */
-static int
-create_maildir(struct mail_storage *storage, struct mail_namespace *ns,
- const char *dir, mode_t mode, gid_t gid, const char *gid_origin,
- bool verify)
+static int create_maildir(struct mailbox *box, bool verify)
{
const char *path;
unsigned int i;
int ret;
if (!verify) {
- ret = maildir_check_tmp(storage, dir);
+ ret = maildir_check_tmp(box->storage, box->path);
if (ret > 0) {
- mail_storage_set_error(storage,
+ mail_storage_set_error(box->storage,
MAIL_ERROR_EXISTS, "Mailbox already exists");
return -1;
}
@@ -314,9 +309,10 @@ create_maildir(struct mail_storage *stor
}
for (i = 0; i < N_ELEMENTS(maildir_subdirs); i++) {
- path = t_strconcat(dir, "/", maildir_subdirs[i], NULL);
- if (mkdir_verify(storage, ns, path, mode, gid,
- gid_origin, verify) < 0)
+ path = t_strconcat(box->path, "/", maildir_subdirs[i], NULL);
+ if (mkdir_verify(box->storage, box->list->ns, path,
+ box->dir_create_mode, box->file_create_gid,
+ box->file_create_gid_origin, verify) < 0)
return -1;
}
return 0;
@@ -325,15 +321,6 @@ static void maildir_lock_touch_timeout(s
static void maildir_lock_touch_timeout(struct maildir_mailbox *mbox)
{
(void)maildir_uidlist_lock_touch(mbox->uidlist);
-}
-
-static mode_t get_dir_mode(mode_t mode)
-{
- /* add the execute bit if either read or write bit is set */
- if ((mode & 0600) != 0) mode |= 0100;
- if ((mode & 0060) != 0) mode |= 0010;
- if ((mode & 0006) != 0) mode |= 0001;
- return mode;
}
static struct mailbox *
@@ -374,26 +361,9 @@ static int maildir_mailbox_open_existing
struct stat st;
const char *shared_path;
- /* for shared mailboxes get the create mode from the
- permissions of dovecot-shared file. */
shared_path = t_strconcat(box->path, "/dovecot-shared", NULL);
- if (stat(shared_path, &st) == 0) {
- if ((st.st_mode & S_ISGID) != 0 ||
- (st.st_mode & 0060) == 0) {
- /* Ignore GID */
- st.st_gid = (gid_t)-1;
- }
- mail_index_set_permissions(mbox->ibox.index,
- st.st_mode & 0666, st.st_gid,
- shared_path);
-
- box->file_create_mode = st.st_mode & 0666;
- box->dir_create_mode = get_dir_mode(st.st_mode & 0666);
- box->file_create_gid = st.st_gid;
- mbox->ibox.box.file_create_gid_origin =
- p_strdup(box->pool, shared_path);
+ if (stat(shared_path, &st) == 0)
box->private_flags_mask = MAIL_SEEN;
- }
if ((box->flags & MAILBOX_FLAG_KEEP_LOCKED) != 0) {
if (maildir_uidlist_lock(mbox->uidlist) <= 0)
@@ -412,9 +382,6 @@ static int maildir_mailbox_open(struct m
static int maildir_mailbox_open(struct mailbox *box)
{
struct stat st;
- const char *gid_origin;
- mode_t mode;
- gid_t gid;
int ret;
bool inbox;
@@ -440,10 +407,7 @@ static int maildir_mailbox_open(struct m
/* tmp/ directory doesn't exist. does the maildir? */
if (inbox || (*box->name != '\0' && stat(box->path, &st) == 0)) {
/* yes, we'll need to create the missing dirs */
- mailbox_list_get_dir_permissions(box->list, box->name,
- &mode, &gid, &gid_origin);
- if (create_maildir(box->storage, box->list->ns, box->path,
- mode, gid, gid_origin, TRUE) < 0)
+ if (create_maildir(box, TRUE) < 0)
return -1;
return maildir_mailbox_open_existing(box);
@@ -458,40 +422,31 @@ static int maildir_mailbox_open(struct m
}
}
-static int
-maildir_create_shared(struct mail_storage *storage, struct mail_namespace *ns,
- const char *dir, mode_t mode, gid_t gid,
- const char *gid_origin)
+static int maildir_create_shared(struct mailbox *box)
{
const char *path;
mode_t old_mask;
int fd;
- /* add the execute bit if either read or write bit is set */
- if ((mode & 0600) != 0) mode |= 0100;
- if ((mode & 0060) != 0) mode |= 0010;
- if ((mode & 0006) != 0) mode |= 0001;
-
- if (create_maildir(storage, ns, dir, mode, gid, gid_origin, FALSE) < 0)
More information about the dovecot-cvs
mailing list