]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added mail_user_get_temp_prefix() and mail_storage_get_temp_prefix().
authorTimo Sirainen <tss@iki.fi>
Thu, 26 Feb 2009 21:43:21 +0000 (16:43 -0500)
committerTimo Sirainen <tss@iki.fi>
Thu, 26 Feb 2009 21:43:21 +0000 (16:43 -0500)
--HG--
branch : HEAD

src/lib-storage/index/maildir/maildir-storage.c
src/lib-storage/index/mbox/mbox-storage.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c
src/lib-storage/mail-storage.h
src/lib-storage/mail-user.c
src/lib-storage/mail-user.h

index cd55eb44968825ebaf434a46d9f899a6a908f1ea..5cb1ff3dbe9364a9e115f972887214c6b7e9629e 100644 (file)
@@ -191,7 +191,7 @@ maildir_create(struct mail_storage *_storage, const char *data,
        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 *_storage, const char *data,
        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;
 }
 
index 12fb02a595d42cbd558dce733832dc7a0b627695..b10d0039b887fa197a4f729b872ec2b0556a6390 100644 (file)
@@ -386,6 +386,9 @@ mbox_list_get_path(struct mailbox_list *list, const char *name,
        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_storage *_storage, const char *data,
 {
        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_storage *_storage, const char *data,
        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;
 }
 
index 3901346f971c41dc88e5a21955e7c0dff76dc489..0beceabb5a3f150a4b92f69b95b82d661e53e1d2 100644 (file)
@@ -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;
index efe5282d838a48021c2306a42b12a44ddee4ad81..138631a8e32cc311643340e81afbbce29ef80199 100644 (file)
@@ -237,7 +237,7 @@ int mail_storage_create(struct mail_namespace *ns, const char *driver,
        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);
@@ -404,6 +404,20 @@ const char *mail_storage_get_mailbox_index_dir(struct mail_storage *storage,
                                     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
 mail_storage_get_list_flags(enum mail_storage_flags storage_flags)
 {
index 2275f1d6b27f06533d90f2dba5fa78a799a75be2..82243668f1d956b8a200ec82739e15d779f15614 100644 (file)
@@ -307,6 +307,8 @@ const char *mail_storage_get_mailbox_control_dir(struct mail_storage *storage,
    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
index adb3290712311089e12b48158f9248792a539e20..84831aec5885d57f59711eb90c84752496f6be51 100644 (file)
@@ -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 mail_user *user, const char **pathp)
        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;
index 15903a5f5915336f5d416fde855c564eaa940cb0..04c15a61b0f565d59d2329f237e318cbe6de52cc 100644 (file)
@@ -59,6 +59,9 @@ void mail_user_set_home(struct mail_user *user, const char *home);
    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. */