]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: If :INDEX=path is specified, keep storage indexes there also.
authorTimo Sirainen <tss@iki.fi>
Mon, 20 Sep 2010 14:30:07 +0000 (15:30 +0100)
committerTimo Sirainen <tss@iki.fi>
Mon, 20 Sep 2010 14:30:07 +0000 (15:30 +0100)
src/lib-storage/index/dbox-multi/mdbox-map-private.h
src/lib-storage/index/dbox-multi/mdbox-map.c
src/lib-storage/index/dbox-multi/mdbox-map.h
src/lib-storage/index/dbox-multi/mdbox-storage.c

index a39432d1845f4ef0b6bd5ef5da51347004e9e0df..94710bb007ac27494442c80704a8637d71b9bcd7 100644 (file)
@@ -12,7 +12,7 @@ struct dbox_mail_lookup_rec {
 struct mdbox_map {
        struct mdbox_storage *storage;
        const struct mdbox_settings *set;
-       char *path;
+       char *path, *index_path;
 
        struct mail_index *index;
        struct mail_index_view *view;
index 77a668a0fe78244b333045c899ec9005f7e4a13b..68fcd5cdd5c7dcba1816936ad0f7df5093c9affb 100644 (file)
@@ -46,16 +46,24 @@ void mdbox_map_set_corrupted(struct mdbox_map *map, const char *format, ...)
 }
 
 struct mdbox_map *
-mdbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list,
-              const char *path)
+mdbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list)
 {
        struct mdbox_map *map;
+       const char *root, *index_root;
+
+       root = mailbox_list_get_path(root_list, NULL,
+                                    MAILBOX_LIST_PATH_TYPE_DIR);
+       index_root = mailbox_list_get_path(root_list, NULL,
+                                          MAILBOX_LIST_PATH_TYPE_INDEX);
 
        map = i_new(struct mdbox_map, 1);
        map->storage = storage;
        map->set = storage->set;
-       map->path = i_strdup(path);
-       map->index = mail_index_alloc(path, MDBOX_GLOBAL_INDEX_PREFIX);
+       map->path = i_strconcat(root, "/"MDBOX_GLOBAL_DIR_NAME, NULL);
+       map->index_path =
+               i_strconcat(index_root, "/"MDBOX_GLOBAL_DIR_NAME, NULL);
+       map->index = mail_index_alloc(map->index_path,
+                                     MDBOX_GLOBAL_INDEX_PREFIX);
        mail_index_set_fsync_mode(map->index,
                MAP_STORAGE(map)->set->parsed_fsync_mode, 0);
        mail_index_set_lock_method(map->index,
@@ -87,18 +95,19 @@ void mdbox_map_deinit(struct mdbox_map **_map)
                mail_index_close(map->index);
        }
        mail_index_free(&map->index);
+       i_free(map->index_path);
        i_free(map->path);
        i_free(map);
 }
 
-static int mdbox_map_mkdir_storage(struct mdbox_map *map)
+static int mdbox_map_mkdir_storage_path(struct mdbox_map *map, const char *path)
 {
        struct stat st;
 
-       if (stat(map->path, &st) == 0)
+       if (stat(path, &st) == 0)
                return 0;
 
-       if (mailbox_list_mkdir(map->root_list, map->path,
+       if (mailbox_list_mkdir(map->root_list, path,
                               MAILBOX_LIST_PATH_TYPE_DIR) < 0) {
                mail_storage_copy_list_error(MAP_STORAGE(map), map->root_list);
                return -1;
@@ -106,6 +115,18 @@ static int mdbox_map_mkdir_storage(struct mdbox_map *map)
        return 0;
 }
 
+static int mdbox_map_mkdir_storage(struct mdbox_map *map)
+{
+       if (mdbox_map_mkdir_storage_path(map, map->path) < 0)
+               return -1;
+
+       if (strcmp(map->path, map->index_path) != 0) {
+               if (mdbox_map_mkdir_storage_path(map, map->index_path) < 0)
+                       return -1;
+       }
+       return 0;
+}
+
 static void mdbox_map_cleanup(struct mdbox_map *map)
 {
        struct stat st;
index 8abe03f6c3b60b4b1125cd099fc276eed96b1c28..0c68e4420cebd4897568faf76ce584f6b65a59d3 100644 (file)
@@ -31,8 +31,7 @@ struct mdbox_map_file_msg {
 ARRAY_DEFINE_TYPE(mdbox_map_file_msg, struct mdbox_map_file_msg);
 
 struct mdbox_map *
-mdbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list,
-              const char *path);
+mdbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list);
 void mdbox_map_deinit(struct mdbox_map **map);
 
 /* Open the map. Returns 1 if ok, 0 if map doesn't exist, -1 if error. */
index 7713c4f8f50e81170f43575c46582812e9a76e46..80952de6b23c8cdd8c3188d8565d1be0c0a19be8 100644 (file)
@@ -59,7 +59,8 @@ mdbox_storage_create(struct mail_storage *_storage, struct mail_namespace *ns,
                                               "/"MDBOX_GLOBAL_DIR_NAME, NULL);
        i_array_init(&storage->open_files, 64);
 
-       storage->map = mdbox_map_init(storage, ns->list, storage->storage_dir);
+       dir = mailbox_list_get_path(ns->list, NULL, MAILBOX_LIST_PATH_TYPE_DIR);
+       storage->map = mdbox_map_init(storage, ns->list);
        return 0;
 }