From: Timo Sirainen Date: Tue, 25 Sep 2012 17:15:58 +0000 (+0300) Subject: lib-storage: Added mailbox_get_path_to() wrapper for mailbox_list_get_path(). X-Git-Tag: 2.2.alpha1~158 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=feaa6a3d82ea61496ced1f83a726ff33047c7da2;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Added mailbox_get_path_to() wrapper for mailbox_list_get_path(). Changed the code to use as much of mailbox_get_path_to() and mailbox_get_path() as possible. --- diff --git a/src/indexer/Makefile.am b/src/indexer/Makefile.am index 36dfda4a77..6781bf7332 100644 --- a/src/indexer/Makefile.am +++ b/src/indexer/Makefile.am @@ -7,6 +7,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib-master \ -I$(top_srcdir)/src/lib-settings \ -I$(top_srcdir)/src/lib-mail \ + -I$(top_srcdir)/src/lib-index \ -I$(top_srcdir)/src/lib-storage \ -DPKG_RUNDIR=\""$(rundir)"\" diff --git a/src/indexer/master-connection.c b/src/indexer/master-connection.c index 4658884a6c..361e210191 100644 --- a/src/indexer/master-connection.c +++ b/src/indexer/master-connection.c @@ -9,7 +9,7 @@ #include "master-service.h" #include "master-service-settings.h" #include "mail-namespace.h" -#include "mail-storage.h" +#include "mail-storage-private.h" #include "mail-storage-service.h" #include "mail-search-build.h" #include "master-connection.h" @@ -130,14 +130,14 @@ index_mailbox(struct master_connection *conn, struct mail_user *user, return -1; } - path = mailbox_list_get_path(ns->list, mailbox, - MAILBOX_LIST_PATH_TYPE_INDEX); + box = mailbox_alloc(ns->list, mailbox, 0); + path = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX); if (*path == '\0') { i_info("Indexes disabled for Mailbox %s, skipping", mailbox); + mailbox_free(&box); return 0; } - - box = mailbox_alloc(ns->list, mailbox, 0); + if (max_recent_msgs != 0) { /* index only if there aren't too many recent messages. don't bother syncing the mailbox, that alone can take a diff --git a/src/lib-storage/index/cydir/cydir-mail.c b/src/lib-storage/index/cydir/cydir-mail.c index 52ab22f548..8796f16d00 100644 --- a/src/lib-storage/index/cydir/cydir-mail.c +++ b/src/lib-storage/index/cydir/cydir-mail.c @@ -13,8 +13,7 @@ static const char *cydir_mail_get_path(struct mail *mail) { const char *dir; - dir = mailbox_list_get_path(mail->box->list, mail->box->name, - MAILBOX_LIST_PATH_TYPE_MAILBOX); + dir = mailbox_get_path(mail->box); return t_strdup_printf("%s/%u.", dir, mail->uid); } diff --git a/src/lib-storage/index/cydir/cydir-save.c b/src/lib-storage/index/cydir/cydir-save.c index 8b1428933d..fca9091676 100644 --- a/src/lib-storage/index/cydir/cydir-save.c +++ b/src/lib-storage/index/cydir/cydir-save.c @@ -50,8 +50,7 @@ cydir_get_save_path(struct cydir_save_context *ctx, unsigned int num) { const char *dir; - dir = mailbox_list_get_path(ctx->mbox->box.list, ctx->mbox->box.name, - MAILBOX_LIST_PATH_TYPE_MAILBOX); + dir = mailbox_get_path(&ctx->mbox->box); return t_strdup_printf("%s/%s.%u", dir, ctx->tmp_basename, num); } @@ -267,8 +266,7 @@ int cydir_transaction_save_commit_pre(struct mail_save_context *_ctx) &_t->changes->saved_uids); _t->changes->uid_validity = ctx->sync_ctx->uid_validity; - dir = mailbox_list_get_path(ctx->mbox->box.list, ctx->mbox->box.name, - MAILBOX_LIST_PATH_TYPE_MAILBOX); + dir = mailbox_get_path(&ctx->mbox->box); src_path = t_str_new(256); str_printfa(src_path, "%s/%s.", dir, ctx->tmp_basename); diff --git a/src/lib-storage/index/cydir/cydir-sync.c b/src/lib-storage/index/cydir/cydir-sync.c index a444c7ce6d..3a57df7ce4 100644 --- a/src/lib-storage/index/cydir/cydir-sync.c +++ b/src/lib-storage/index/cydir/cydir-sync.c @@ -19,11 +19,8 @@ static void cydir_sync_set_uidvalidity(struct cydir_sync_context *ctx) static string_t *cydir_get_path_prefix(struct cydir_mailbox *mbox) { string_t *path = str_new(default_pool, 256); - const char *dir; - dir = mailbox_list_get_path(mbox->box.list, mbox->box.name, - MAILBOX_LIST_PATH_TYPE_MAILBOX); - str_append(path, dir); + str_append(path, mailbox_get_path(&mbox->box)); str_append_c(path, '/'); return path; } diff --git a/src/lib-storage/index/dbox-common/dbox-storage.c b/src/lib-storage/index/dbox-common/dbox-storage.c index 46ffa0d478..db818a113a 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.c +++ b/src/lib-storage/index/dbox-common/dbox-storage.c @@ -139,8 +139,7 @@ void dbox_notify_changes(struct mailbox *box) if (box->notify_callback == NULL) index_mailbox_check_remove_all(box); else { - dir = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_INDEX); + dir = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX); path = t_strdup_printf("%s/"DBOX_INDEX_PREFIX".log", dir); index_mailbox_check_add(box, path); } @@ -252,8 +251,7 @@ int dbox_mailbox_create(struct mailbox *box, /* if alt path already exists and contains files, rebuild storage so that we don't start overwriting files. */ - alt_path = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX); + alt_path = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX); if (alt_path != NULL && stat(alt_path, &st) == 0) { ret = dir_is_empty(box->storage, alt_path); if (ret < 0) diff --git a/src/lib-storage/index/dbox-single/sdbox-file.c b/src/lib-storage/index/dbox-single/sdbox-file.c index ae04d04c78..7bf24f1a78 100644 --- a/src/lib-storage/index/dbox-single/sdbox-file.c +++ b/src/lib-storage/index/dbox-single/sdbox-file.c @@ -25,8 +25,7 @@ static void sdbox_file_init_paths(struct sdbox_file *file, const char *fname) file->file.primary_path = i_strdup_printf("%s/%s", mailbox_get_path(box), fname); - alt_path = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX); + alt_path = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX); if (alt_path != NULL) file->file.alt_path = i_strdup_printf("%s/%s", alt_path, fname); } diff --git a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c index 734c3d13f3..7044200ab5 100644 --- a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c +++ b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c @@ -159,8 +159,8 @@ sdbox_sync_index_rebuild_singles(struct index_rebuild_context *ctx) int ret = 0; path = mailbox_get_path(ctx->box); - alt_path = mailbox_list_get_path(ctx->box->list, ctx->box->name, - MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX); + alt_path = mailbox_get_path_to(ctx->box, + MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX); sdbox_sync_set_uidvalidity(ctx); if (sdbox_sync_index_rebuild_dir(ctx, path, TRUE) < 0) { diff --git a/src/lib-storage/index/index-rebuild.c b/src/lib-storage/index/index-rebuild.c index 7e0c4e65b0..28e0cf0393 100644 --- a/src/lib-storage/index/index-rebuild.c +++ b/src/lib-storage/index/index-rebuild.c @@ -167,8 +167,7 @@ index_index_rebuild_init(struct mailbox *box, struct mail_index_view *view, mail_cache_reset(box->cache); /* if backup index file exists, try to use it */ - index_dir = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_INDEX); + index_dir = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX); backup_path = t_strconcat(box->index_prefix, "/.backup", NULL); ctx->backup_index = mail_index_alloc(index_dir, backup_path); diff --git a/src/lib-storage/index/index-storage.c b/src/lib-storage/index/index-storage.c index c8dcf1a7f5..d61599d8ce 100644 --- a/src/lib-storage/index/index-storage.c +++ b/src/lib-storage/index/index-storage.c @@ -139,11 +139,9 @@ index_mailbox_alloc_index(struct mailbox *box) { const char *index_dir, *mailbox_path; - mailbox_path = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_MAILBOX); + mailbox_path = mailbox_get_path(box); index_dir = (box->flags & MAILBOX_FLAG_NO_INDEX_FILES) != 0 ? "" : - mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_INDEX); + mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX); if (*index_dir == '\0') index_dir = NULL; @@ -165,8 +163,7 @@ int index_storage_mailbox_exists_full(struct mailbox *box, const char *subdir, const char *path, *path2; /* see if it's selectable */ - path = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_MAILBOX); + path = mailbox_get_path(box); if (subdir != NULL) path = t_strconcat(path, "/", subdir, NULL); if (stat(path, &st) == 0) { @@ -180,8 +177,7 @@ int index_storage_mailbox_exists_full(struct mailbox *box, const char *subdir, } /* see if it's non-selectable */ - path2 = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_DIR); + path2 = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_DIR); if (strcmp(path, path2) != 0 && stat(path2, &st) == 0) { *existence_r = MAILBOX_EXISTENCE_NOSELECT; diff --git a/src/lib-storage/index/index-sync-pvt.c b/src/lib-storage/index/index-sync-pvt.c index 9eecd610bc..6cec307f7d 100644 --- a/src/lib-storage/index/index-sync-pvt.c +++ b/src/lib-storage/index/index-sync-pvt.c @@ -12,8 +12,7 @@ static int index_storage_mailbox_alloc_index_pvt(struct mailbox *box) if (box->index_pvt != NULL) return 1; - index_dir = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE); + index_dir = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE); if (index_dir == NULL) { /* no private indexes */ return 0; diff --git a/src/lib-storage/index/index-sync.c b/src/lib-storage/index/index-sync.c index 7d467507e9..f09183a7da 100644 --- a/src/lib-storage/index/index-sync.c +++ b/src/lib-storage/index/index-sync.c @@ -485,8 +485,7 @@ int index_storage_list_index_has_changed(struct mailbox *box, return 1; } - dir = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_INDEX); + dir = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX); path = t_strconcat(dir, "/", box->index_prefix, ".log", NULL); if (stat(path, &st) < 0) { if (errno == ENOENT) @@ -525,8 +524,7 @@ void index_storage_list_index_update_sync(struct mailbox *box, return; old_rec = data; - dir = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_INDEX); + dir = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX); path = t_strconcat(dir, "/", box->index_prefix, ".log", NULL); if (stat(path, &st) < 0) { mail_storage_set_critical(box->storage, diff --git a/src/lib-storage/index/maildir/maildir-keywords.c b/src/lib-storage/index/maildir/maildir-keywords.c index 23f58134ba..36465099b3 100644 --- a/src/lib-storage/index/maildir/maildir-keywords.c +++ b/src/lib-storage/index/maildir/maildir-keywords.c @@ -66,8 +66,7 @@ maildir_keywords_init_readonly(struct mailbox *box) struct maildir_keywords *mk; const char *dir; - dir = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_CONTROL); + dir = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_CONTROL); mk = i_new(struct maildir_keywords, 1); mk->storage = box->storage; diff --git a/src/lib-storage/index/maildir/maildir-sync-index.c b/src/lib-storage/index/maildir/maildir-sync-index.c index e85f616813..ab3d439a5d 100644 --- a/src/lib-storage/index/maildir/maildir-sync-index.c +++ b/src/lib-storage/index/maildir/maildir-sync-index.c @@ -728,8 +728,7 @@ int maildir_list_index_has_changed(struct mailbox *box, return 1; } - root_dir = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_MAILBOX); + root_dir = mailbox_get_path(box); /* check if new/ changed */ new_dir = t_strconcat(root_dir, "/new", NULL); diff --git a/src/lib-storage/index/maildir/maildir-uidlist.c b/src/lib-storage/index/maildir/maildir-uidlist.c index be36f01448..5ffbc2362c 100644 --- a/src/lib-storage/index/maildir/maildir-uidlist.c +++ b/src/lib-storage/index/maildir/maildir-uidlist.c @@ -154,10 +154,9 @@ static int maildir_uidlist_lock_timeout(struct maildir_uidlist *uidlist, return 1; } - index_storage_lock_notify_reset(uidlist->box); + index_storage_lock_notify_reset(box); - control_dir = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_CONTROL); + control_dir = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_CONTROL); path = t_strconcat(control_dir, "/" MAILDIR_UIDLIST_NAME, NULL); for (i = 0;; i++) { @@ -265,8 +264,7 @@ struct maildir_uidlist *maildir_uidlist_init(struct maildir_mailbox *mbox) struct maildir_uidlist *uidlist; const char *control_dir; - control_dir = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_CONTROL); + control_dir = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_CONTROL); uidlist = i_new(struct maildir_uidlist, 1); uidlist->box = box; @@ -1396,8 +1394,7 @@ static int maildir_uidlist_recreate(struct maildir_uidlist *uidlist) maildir_uidlist_records_drop_expunges(uidlist); - control_dir = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_CONTROL); + control_dir = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_CONTROL); temp_path = t_strconcat(control_dir, "/" MAILDIR_UIDLIST_NAME ".tmp", NULL); @@ -1760,7 +1757,7 @@ int maildir_uidlist_sync_next_uid(struct maildir_uidlist_sync_ctx *ctx, { struct maildir_uidlist *uidlist = ctx->uidlist; struct maildir_uidlist_rec *rec, *old_rec; - const char *p, *dir; + const char *p; *rec_r = NULL; @@ -1768,12 +1765,8 @@ int maildir_uidlist_sync_next_uid(struct maildir_uidlist_sync_ctx *ctx, return -1; for (p = filename; *p != '\0'; p++) { if (*p == 13 || *p == 10) { - struct mailbox *box = uidlist->box; - - dir = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_MAILBOX); i_warning("Maildir %s: Ignoring a file with #0x%x: %s", - dir, *p, filename); + mailbox_get_path(uidlist->box), *p, filename); return 1; } } diff --git a/src/lib-storage/index/maildir/maildir-util.c b/src/lib-storage/index/maildir/maildir-util.c index 9c19f0a58f..c93e6ea553 100644 --- a/src/lib-storage/index/maildir/maildir-util.c +++ b/src/lib-storage/index/maildir/maildir-util.c @@ -217,11 +217,9 @@ static int maildir_create_subdirs(struct mailbox *box) "/", subdirs[i], NULL); } types[i] = MAILBOX_LIST_PATH_TYPE_CONTROL; - dirs[i++] = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_CONTROL); + dirs[i++] = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_CONTROL); types[i] = MAILBOX_LIST_PATH_TYPE_INDEX; - dirs[i++] = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_INDEX); + dirs[i++] = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX); i_assert(i == N_ELEMENTS(dirs)); for (i = 0; i < N_ELEMENTS(dirs); i++) { diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index 79f4583367..9a6c86d0ec 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -501,8 +501,7 @@ static int create_inbox(struct mailbox *box) const char *inbox_path; int fd; - inbox_path = mailbox_list_get_path(box->list, "INBOX", - MAILBOX_LIST_PATH_TYPE_MAILBOX); + inbox_path = mailbox_get_path(box); fd = open(inbox_path, O_RDWR | O_CREAT | O_EXCL, 0660); if (fd == -1 && errno == EACCES) { diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index e2d80279ed..2891a8a97c 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -558,6 +558,9 @@ void mailbox_set_deleted(struct mailbox *box); int mailbox_mark_index_deleted(struct mailbox *box, bool del); /* Easy wrapper for getting mailbox's MAILBOX_LIST_PATH_TYPE_MAILBOX */ const char *mailbox_get_path(struct mailbox *box) ATTR_PURE; +/* Returns path to specified type of files in mailbox. */ +const char * +mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type); /* Get mailbox permissions. */ const struct mailbox_permissions *mailbox_get_permissions(struct mailbox *box); /* Force permissions to be refreshed on next lookup */ diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index ebc761af68..58c9d7174e 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -1797,13 +1797,18 @@ void mailbox_set_deleted(struct mailbox *box) box->mailbox_deleted = TRUE; } +const char * +mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type) +{ + return mailbox_list_get_path(box->list, box->name, type); +} + const char *mailbox_get_path(struct mailbox *box) { const char *path; if (box->_path == NULL) { - path = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_MAILBOX); + path = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_MAILBOX); box->_path = p_strdup(box->pool, path); } return box->_path; diff --git a/src/plugins/acl/doveadm-acl.c b/src/plugins/acl/doveadm-acl.c index 722f980ce5..8c2817ac1b 100644 --- a/src/plugins/acl/doveadm-acl.c +++ b/src/plugins/acl/doveadm-acl.c @@ -418,8 +418,7 @@ cmd_acl_debug_mailbox_open(struct doveadm_mail_cmd_context *ctx, box = mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_READONLY | MAILBOX_FLAG_IGNORE_ACLS); if (mailbox_open(box) < 0) { - path = mailbox_list_get_path(ns->list, box->name, - MAILBOX_LIST_PATH_TYPE_MAILBOX); + path = mailbox_get_path(box); errstr = mail_storage_get_last_error(box->storage, &error); doveadm_mail_failed_error(ctx, error); if (error != MAIL_ERROR_NOTFOUND || diff --git a/src/plugins/fts-squat/fts-backend-squat.c b/src/plugins/fts-squat/fts-backend-squat.c index 8e9af00836..3e7f0b4d4a 100644 --- a/src/plugins/fts-squat/fts-backend-squat.c +++ b/src/plugins/fts-squat/fts-backend-squat.c @@ -115,8 +115,7 @@ fts_backend_squat_set_box(struct squat_fts_backend *backend, perm = mailbox_get_permissions(box); storage = mailbox_get_storage(box); - path = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_INDEX); + path = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX); i_assert(*path != '\0'); /* fts already checked this */ mailbox_get_open_status(box, STATUS_UIDVALIDITY, &status); diff --git a/src/plugins/quota/quota-fs.c b/src/plugins/quota/quota-fs.c index 4da0e52fe9..010d937103 100644 --- a/src/plugins/quota/quota-fs.c +++ b/src/plugins/quota/quota-fs.c @@ -770,8 +770,7 @@ static bool fs_quota_match_box(struct quota_root *_root, struct mailbox *box) if (root->storage_mount_path == NULL) return TRUE; - mailbox_path = mailbox_list_get_path(box->list, box->name, - MAILBOX_LIST_PATH_TYPE_MAILBOX); + mailbox_path = mailbox_get_path(box); if (stat(mailbox_path, &mst) < 0) { if (errno != ENOENT) i_error("stat(%s) failed: %m", mailbox_path);