dovecot-1.2: Added mail_user_get_temp_prefix() and mail_storage_...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Feb 26 23:43:59 EET 2009
details: http://hg.dovecot.org/dovecot-1.2/rev/db9811ec1f47
changeset: 8786:db9811ec1f47
user: Timo Sirainen <tss at iki.fi>
date: Thu Feb 26 16:43:21 2009 -0500
description:
Added mail_user_get_temp_prefix() and mail_storage_get_temp_prefix().
diffstat:
7 files changed, 66 insertions(+), 8 deletions(-)
src/lib-storage/index/maildir/maildir-storage.c | 20 ++++++++++++++------
src/lib-storage/index/mbox/mbox-storage.c | 15 ++++++++++++++-
src/lib-storage/mail-storage-private.h | 1 +
src/lib-storage/mail-storage.c | 16 +++++++++++++++-
src/lib-storage/mail-storage.h | 2 ++
src/lib-storage/mail-user.c | 17 +++++++++++++++++
src/lib-storage/mail-user.h | 3 +++
diffs (182 lines):
diff -r 3d11825abf66 -r db9811ec1f47 src/lib-storage/index/maildir/maildir-storage.c
--- a/src/lib-storage/index/maildir/maildir-storage.c Thu Feb 26 16:42:00 2009 -0500
+++ b/src/lib-storage/index/maildir/maildir-storage.c Thu Feb 26 16:43:21 2009 -0500
@@ -191,7 +191,7 @@ maildir_create(struct mail_storage *_sto
enum mail_storage_flags flags = _storage->flags;
struct mailbox_list_settings list_set;
struct mailbox_list *list;
- const char *layout;
+ const char *layout, *dir;
struct stat st;
if (maildir_get_list_settings(&list_set, data, _storage, &layout,
@@ -258,12 +258,20 @@ maildir_create(struct mail_storage *_sto
storage->stat_dirs = getenv("MAILDIR_STAT_DIRS") != NULL;
storage->temp_prefix = mailbox_list_get_temp_prefix(list);
- if (list_set.control_dir == NULL) {
+ if (list_set.control_dir == NULL &&
+ (_storage->ns->flags & NAMESPACE_FLAG_INBOX) != 0) {
/* put the temp files into tmp/ directory preferrably */
- storage->temp_prefix =
- p_strconcat(_storage->pool,
- "tmp/", storage->temp_prefix, NULL);
- }
+ storage->temp_prefix = p_strconcat(_storage->pool, "tmp/",
+ storage->temp_prefix, NULL);
+ dir = mailbox_list_get_path(list, NULL,
+ MAILBOX_LIST_PATH_TYPE_DIR);
+ } else {
+ /* control dir should also be writable */
+ dir = mailbox_list_get_path(list, NULL,
+ MAILBOX_LIST_PATH_TYPE_CONTROL);
+ }
+ _storage->temp_path_prefix = p_strconcat(_storage->pool, dir, "/",
+ storage->temp_prefix, NULL);
return 0;
}
diff -r 3d11825abf66 -r db9811ec1f47 src/lib-storage/index/mbox/mbox-storage.c
--- a/src/lib-storage/index/mbox/mbox-storage.c Thu Feb 26 16:42:00 2009 -0500
+++ b/src/lib-storage/index/mbox/mbox-storage.c Thu Feb 26 16:43:21 2009 -0500
@@ -386,6 +386,9 @@ mbox_list_get_path(struct mailbox_list *
path = storage->list_module_ctx.super.get_path(list, name, type);
if (type == MAILBOX_LIST_PATH_TYPE_CONTROL ||
type == MAILBOX_LIST_PATH_TYPE_INDEX) {
+ if (name == NULL)
+ return t_strconcat(path, "/"MBOX_INDEX_DIR_NAME, NULL);
+
p = strrchr(path, '/');
if (p == NULL)
return "";
@@ -442,7 +445,7 @@ static int mbox_create(struct mail_stora
{
struct mbox_storage *storage = (struct mbox_storage *)_storage;
struct mailbox_list_settings list_set;
- const char *layout;
+ const char *layout, *dir;
if (mbox_get_list_settings(&list_set, data, _storage,
&layout, error_r) < 0)
@@ -470,6 +473,16 @@ static int mbox_create(struct mail_stora
mailbox_list_init(_storage->list, _storage->ns, &list_set,
mail_storage_get_list_flags(_storage->flags) |
MAILBOX_LIST_FLAG_MAILBOX_FILES);
+
+ dir = mailbox_list_get_path(_storage->list, NULL,
+ MAILBOX_LIST_PATH_TYPE_INDEX);
+ if (*dir == '\0') {
+ /* no index directory. just fallback to writing to root. */
+ dir = mailbox_list_get_path(_storage->list, NULL,
+ MAILBOX_LIST_PATH_TYPE_DIR);
+ }
+ _storage->temp_path_prefix = p_strconcat(_storage->pool, dir, "/",
+ mailbox_list_get_temp_prefix(_storage->list), NULL);
return 0;
}
diff -r 3d11825abf66 -r db9811ec1f47 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h Thu Feb 26 16:42:00 2009 -0500
+++ b/src/lib-storage/mail-storage-private.h Thu Feb 26 16:43:21 2009 -0500
@@ -61,6 +61,7 @@ struct mail_storage {
const struct mail_storage *storage_class;
struct mail_namespace *ns;
struct mailbox_list *list;
+ const char *temp_path_prefix;
enum mail_storage_flags flags;
enum file_lock_method lock_method;
diff -r 3d11825abf66 -r db9811ec1f47 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c Thu Feb 26 16:42:00 2009 -0500
+++ b/src/lib-storage/mail-storage.c Thu Feb 26 16:43:21 2009 -0500
@@ -237,7 +237,7 @@ int mail_storage_create(struct mail_name
value = getenv("MAIL_MAX_KEYWORD_LENGTH");
storage->keyword_max_len = value != NULL ?
atoi(value) : DEFAULT_MAX_KEYWORD_LENGTH;
-
+
if (hook_mail_storage_created != NULL) {
T_BEGIN {
hook_mail_storage_created(storage);
@@ -402,6 +402,20 @@ const char *mail_storage_get_mailbox_ind
return mailbox_list_get_path(storage->list, name,
MAILBOX_LIST_PATH_TYPE_INDEX);
+}
+
+const char *mail_storage_get_temp_prefix(struct mail_storage *storage)
+{
+ const char *dir;
+
+ if (storage->temp_path_prefix == NULL) {
+ dir = mailbox_list_get_path(storage->list, NULL,
+ MAILBOX_LIST_PATH_TYPE_DIR);
+ storage->temp_path_prefix = p_strconcat(storage->pool, dir, "/",
+ mailbox_list_get_temp_prefix(storage->list), NULL);
+ }
+
+ return storage->temp_path_prefix;
}
enum mailbox_list_flags
diff -r 3d11825abf66 -r db9811ec1f47 src/lib-storage/mail-storage.h
--- a/src/lib-storage/mail-storage.h Thu Feb 26 16:42:00 2009 -0500
+++ b/src/lib-storage/mail-storage.h Thu Feb 26 16:43:21 2009 -0500
@@ -307,6 +307,8 @@ const char *mail_storage_get_mailbox_con
in-memory indexes or mailbox doesn't exist. */
const char *mail_storage_get_mailbox_index_dir(struct mail_storage *storage,
const char *name);
+/* Returns path + file prefix for creating a temporary file. */
+const char *mail_storage_get_temp_prefix(struct mail_storage *storage);
/* Open a mailbox. If input stream is given, mailbox is opened read-only
using it as a backend. If storage doesn't support stream backends and its
diff -r 3d11825abf66 -r db9811ec1f47 src/lib-storage/mail-user.c
--- a/src/lib-storage/mail-user.c Thu Feb 26 16:42:00 2009 -0500
+++ b/src/lib-storage/mail-user.c Thu Feb 26 16:43:21 2009 -0500
@@ -2,8 +2,10 @@
#include "lib.h"
#include "array.h"
+#include "hostpid.h"
#include "auth-master.h"
#include "mail-namespace.h"
+#include "mail-storage.h"
#include "mail-user.h"
#include <stdlib.h>
@@ -157,6 +159,21 @@ int mail_user_try_home_expand(struct mai
return 0;
}
+const char *mail_user_get_temp_prefix(struct mail_user *user)
+{
+ struct mail_namespace *ns;
+
+ if (user->_home != NULL) {
+ return t_strconcat(user->_home, "/.temp.", my_hostname, ".",
+ my_pid, ".", NULL);
+ }
+
+ ns = mail_namespace_find_inbox(user->namespaces);
+ if (ns == NULL)
+ ns = user->namespaces;
+ return mail_storage_get_temp_prefix(ns->storage);
+}
+
void mail_users_init(const char *auth_socket_path, bool debug)
{
const char *base_dir;
diff -r 3d11825abf66 -r db9811ec1f47 src/lib-storage/mail-user.h
--- a/src/lib-storage/mail-user.h Thu Feb 26 16:42:00 2009 -0500
+++ b/src/lib-storage/mail-user.h Thu Feb 26 16:43:21 2009 -0500
@@ -59,6 +59,9 @@ void mail_user_set_home(struct mail_user
successfully, 0 if there is no home directory (either user doesn't exist or
has no home directory) or -1 if lookup failed. */
int mail_user_get_home(struct mail_user *user, const char **home_r);
+/* Returns path + file prefix for creating a temporary file. Uses home
+ directory if possible, fallbacks to mail directory. */
+const char *mail_user_get_temp_prefix(struct mail_user *user);
/* Add more namespaces to user's namespaces. The ->next pointers may be
changed, so the namespaces pointer will be updated to user->namespaces. */
More information about the dovecot-cvs
mailing list