From: Timo Sirainen Date: Fri, 10 Apr 2009 17:16:16 +0000 (-0400) Subject: Added mail_storage_purge() for dbox. dbox no longer calls it automatically at logout. X-Git-Tag: 2.0.alpha1~991 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3e564425db51f3921ce4de11859777135fdedd15;p=thirdparty%2Fdovecot%2Fcore.git Added mail_storage_purge() for dbox. dbox no longer calls it automatically at logout. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/cydir/cydir-storage.c b/src/lib-storage/index/cydir/cydir-storage.c index 0ebadc7842..70569cf422 100644 --- a/src/lib-storage/index/cydir/cydir-storage.c +++ b/src/lib-storage/index/cydir/cydir-storage.c @@ -414,7 +414,8 @@ struct mail_storage cydir_storage = { index_storage_destroy, NULL, cydir_mailbox_open, - cydir_mailbox_create + cydir_mailbox_create, + NULL } }; diff --git a/src/lib-storage/index/dbox/dbox-storage.c b/src/lib-storage/index/dbox/dbox-storage.c index cb0c6e1b4c..fae4048641 100644 --- a/src/lib-storage/index/dbox/dbox-storage.c +++ b/src/lib-storage/index/dbox/dbox-storage.c @@ -191,7 +191,6 @@ static void dbox_destroy(struct mail_storage *_storage) return; } - dbox_sync_purge(storage); dbox_files_free(storage); dbox_map_deinit(&storage->map); array_free(&storage->open_files); @@ -773,7 +772,8 @@ struct mail_storage dbox_storage = { dbox_destroy, NULL, dbox_mailbox_open, - dbox_mailbox_create + dbox_mailbox_create, + dbox_sync_purge } }; diff --git a/src/lib-storage/index/dbox/dbox-sync.c b/src/lib-storage/index/dbox/dbox-sync.c index c81cb8d389..24dbb25f76 100644 --- a/src/lib-storage/index/dbox/dbox-sync.c +++ b/src/lib-storage/index/dbox/dbox-sync.c @@ -350,23 +350,28 @@ dbox_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) return index_mailbox_sync_init(box, flags, ret < 0); } -void dbox_sync_purge(struct dbox_storage *storage) +int dbox_sync_purge(struct mail_storage *_storage) { + struct dbox_storage *storage = (struct dbox_storage *)_storage; const ARRAY_TYPE(seq_range) *ref0_file_ids; struct dbox_file *file; struct seq_range_iter iter; unsigned int i = 0; uint32_t file_id; bool deleted; + int ret = 0; ref0_file_ids = dbox_map_get_zero_ref_files(storage->map); seq_range_array_iter_init(&iter, ref0_file_ids); i = 0; while (seq_range_array_iter_nth(&iter, i++, &file_id)) T_BEGIN { file = dbox_file_init_multi(storage, file_id); - if (dbox_file_open_or_create(file, &deleted) > 0 && !deleted) - (void)dbox_sync_file_purge(file); - else + if (dbox_file_open_or_create(file, &deleted) > 0 && !deleted) { + if (dbox_sync_file_purge(file) < 0) + ret = -1; + } else { dbox_map_remove_file_id(storage->map, file_id); + } dbox_file_unref(&file); } T_END; + return ret; } diff --git a/src/lib-storage/index/dbox/dbox-sync.h b/src/lib-storage/index/dbox/dbox-sync.h index c90c813429..439e1f770a 100644 --- a/src/lib-storage/index/dbox/dbox-sync.h +++ b/src/lib-storage/index/dbox/dbox-sync.h @@ -37,7 +37,7 @@ int dbox_sync_begin(struct dbox_mailbox *mbox, enum dbox_sync_flags flags, int dbox_sync_finish(struct dbox_sync_context **ctx, bool success); int dbox_sync(struct dbox_mailbox *mbox); -void dbox_sync_purge(struct dbox_storage *storage); +int dbox_sync_purge(struct mail_storage *storage); int dbox_sync_file(struct dbox_sync_context *ctx, const struct dbox_sync_file_entry *entry); int dbox_sync_file_purge(struct dbox_file *file); diff --git a/src/lib-storage/index/maildir/maildir-storage.c b/src/lib-storage/index/maildir/maildir-storage.c index 35b7094e2f..0f7d63fda0 100644 --- a/src/lib-storage/index/maildir/maildir-storage.c +++ b/src/lib-storage/index/maildir/maildir-storage.c @@ -1084,7 +1084,8 @@ struct mail_storage maildir_storage = { index_storage_destroy, maildir_autodetect, maildir_mailbox_open, - maildir_mailbox_create + maildir_mailbox_create, + NULL } }; diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index ece0237fe7..d35f0fab20 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -1006,7 +1006,8 @@ struct mail_storage mbox_storage = { index_storage_destroy, mbox_autodetect, mbox_mailbox_open, - mbox_mailbox_create + mbox_mailbox_create, + NULL } }; diff --git a/src/lib-storage/index/raw/raw-storage.c b/src/lib-storage/index/raw/raw-storage.c index 6cab2f30ab..43404bc226 100644 --- a/src/lib-storage/index/raw/raw-storage.c +++ b/src/lib-storage/index/raw/raw-storage.c @@ -266,7 +266,8 @@ struct mail_storage raw_storage = { index_storage_destroy, NULL, raw_mailbox_open, - raw_mailbox_create + raw_mailbox_create, + NULL } }; diff --git a/src/lib-storage/index/shared/shared-storage.c b/src/lib-storage/index/shared/shared-storage.c index fec0a32315..58dc31f30c 100644 --- a/src/lib-storage/index/shared/shared-storage.c +++ b/src/lib-storage/index/shared/shared-storage.c @@ -325,6 +325,7 @@ struct mail_storage shared_storage = { index_storage_destroy, NULL, NULL, - shared_mailbox_create + shared_mailbox_create, + NULL } }; diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 221934ab35..adf5bfd358 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -42,6 +42,7 @@ struct mail_storage_vfuncs { int (*mailbox_create)(struct mail_storage *storage, const char *name, bool directory); + int (*purge)(struct mail_storage *storage); }; union mail_storage_module_context { diff --git a/src/lib-storage/mail-storage-service.c b/src/lib-storage/mail-storage-service.c index 7ce54b6ab4..2d79244a24 100644 --- a/src/lib-storage/mail-storage-service.c +++ b/src/lib-storage/mail-storage-service.c @@ -353,6 +353,9 @@ mail_storage_service_init_user(struct master_service *service, const char *user, userdb_lookup = (flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0; mail_storage_service_init_settings(service, set_root, !userdb_lookup); + if ((flags & MAIL_STORAGE_SERVICE_FLAG_DEBUG) != 0) + master_service_set(service, "mail_debug", "yes"); + /* now that we've read settings, we can set up logging */ master_service_init_log(service, t_strdup_printf("%s(%s): ", service->name, user)); diff --git a/src/lib-storage/mail-storage-service.h b/src/lib-storage/mail-storage-service.h index 2e6a035631..2e9077335c 100644 --- a/src/lib-storage/mail-storage-service.h +++ b/src/lib-storage/mail-storage-service.h @@ -2,8 +2,12 @@ #define MAIL_STORAGE_SERVICE_H enum mail_storage_service_flags { + /* Fail if we don't drop root privileges */ MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT = 0x01, - MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP = 0x02 + /* Lookup user from userdb */ + MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP = 0x02, + /* Force mail_debug=yes */ + MAIL_STORAGE_SERVICE_FLAG_DEBUG = 0x04 }; struct setting_parser_info; diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 588cb38693..866f405c32 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -331,6 +331,14 @@ int mail_storage_mailbox_create(struct mail_storage *storage, const char *name, return storage->v.mailbox_create(storage, name, directory); } +int mail_storage_purge(struct mail_storage *storage) +{ + mail_storage_clear_error(storage); + + return storage->v.purge == NULL ? 0 : + storage->v.purge(storage); +} + const char *mail_storage_get_last_error(struct mail_storage *storage, enum mail_error *error_r) { diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index b0e7903950..af1b82b929 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -271,6 +271,9 @@ void mail_storage_set_callbacks(struct mail_storage *storage, created as long as it shows in LIST. */ int mail_storage_mailbox_create(struct mail_storage *storage, const char *name, bool directory); +/* Purge storage's mailboxes (freeing disk space from expunged mails), + if supported by the storage. Otherwise just a no-op. */ +int mail_storage_purge(struct mail_storage *storage); /* Returns the error message of last occurred error. */ const char *mail_storage_get_last_error(struct mail_storage *storage,