From: Timo Sirainen Date: Mon, 20 Sep 2010 14:30:07 +0000 (+0100) Subject: mdbox: If :INDEX=path is specified, keep storage indexes there also. X-Git-Tag: 2.0.4~46 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=02d72ab3d606033e9a720274ddc3dd83a0ad070d;p=thirdparty%2Fdovecot%2Fcore.git mdbox: If :INDEX=path is specified, keep storage indexes there also. --- diff --git a/src/lib-storage/index/dbox-multi/mdbox-map-private.h b/src/lib-storage/index/dbox-multi/mdbox-map-private.h index a39432d184..94710bb007 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map-private.h +++ b/src/lib-storage/index/dbox-multi/mdbox-map-private.h @@ -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; diff --git a/src/lib-storage/index/dbox-multi/mdbox-map.c b/src/lib-storage/index/dbox-multi/mdbox-map.c index 77a668a0fe..68fcd5cdd5 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map.c +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c @@ -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; diff --git a/src/lib-storage/index/dbox-multi/mdbox-map.h b/src/lib-storage/index/dbox-multi/mdbox-map.h index 8abe03f6c3..0c68e4420c 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map.h +++ b/src/lib-storage/index/dbox-multi/mdbox-map.h @@ -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. */ diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index 7713c4f8f5..80952de6b2 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -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; }