dovecot-2.2: plugins/fts: expunge-log - permit append helpers to...

dovecot at dovecot.org dovecot at dovecot.org
Tue Jan 20 23:55:04 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/5091f03d70e1
changeset: 18192:5091f03d70e1
user:      Phil Carmody <phil at dovecot.fi>
date:      Wed Jan 21 01:47:25 2015 +0200
description:
plugins/fts: expunge-log - permit append helpers to have no log to write to
This is for creating an in-RAM, later queriable, structure which you do not
want to be written to backing storage. As when you've finished with one, there's
no concept of a "commit", provide an alternative "abort" way out. These are
identical apart from the call to the write() routine, so refactor the two.

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/plugins/fts/fts-expunge-log.c |  27 +++++++++++++--------------
 src/plugins/fts/fts-expunge-log.h |   2 ++
 2 files changed, 15 insertions(+), 14 deletions(-)

diffs (75 lines):

diff -r 2e756ad0ffcf -r 5091f03d70e1 src/plugins/fts/fts-expunge-log.c
--- a/src/plugins/fts/fts-expunge-log.c	Wed Jan 21 01:46:13 2015 +0200
+++ b/src/plugins/fts/fts-expunge-log.c	Wed Jan 21 01:47:25 2015 +0200
@@ -182,7 +182,7 @@
 	ctx->pool = pool;
 	hash_table_create(&ctx->mailboxes, pool, 0, guid_128_hash, guid_128_cmp);
 
-	if (fts_expunge_log_reopen_if_needed(log, TRUE) < 0)
+	if (log != NULL && fts_expunge_log_reopen_if_needed(log, TRUE) < 0)
 		ctx->failed = TRUE;
 	return ctx;
 }
@@ -266,6 +266,9 @@
 	uint32_t expunge_count, *e;
 	int ret;
 
+	/* Unbacked expunge logs cannot be written, by definition */
+	i_assert(log != NULL);
+
 	/* try to append to the latest file */
 	if (fts_expunge_log_reopen_if_needed(log, TRUE) < 0)
 		return -1;
@@ -311,31 +314,27 @@
 	return ret;
 }
 
-int fts_expunge_log_append_commit(struct fts_expunge_log_append_ctx **_ctx)
+static int fts_expunge_log_append_finalise(struct fts_expunge_log_append_ctx **_ctx,
+					   bool commit)
 {
 	struct fts_expunge_log_append_ctx *ctx = *_ctx;
 	int ret = ctx->failed ? -1 : 0;
 
 	*_ctx = NULL;
-	if (ret == 0)
+	if (commit && ret == 0)
 		ret = fts_expunge_log_write(ctx);
 
 	hash_table_destroy(&ctx->mailboxes);
 	pool_unref(&ctx->pool);
 	return ret;
 }
-
-int fts_expunge_log_uid_count(struct fts_expunge_log *log,
-			      unsigned int *expunges_r)
+int fts_expunge_log_append_commit(struct fts_expunge_log_append_ctx **_ctx)
 {
-	int ret;
-
-	if ((ret = fts_expunge_log_reopen_if_needed(log, FALSE)) <= 0) {
-		*expunges_r = 0;
-		return ret;
-	}
-
-	return fts_expunge_log_read_expunge_count(log, expunges_r);
+	return fts_expunge_log_append_finalise(_ctx, TRUE);
+}
+int fts_expunge_log_append_abort(struct fts_expunge_log_append_ctx **_ctx)
+{
+	return fts_expunge_log_append_finalise(_ctx, FALSE);
 }
 
 struct fts_expunge_log_read_ctx *
diff -r 2e756ad0ffcf -r 5091f03d70e1 src/plugins/fts/fts-expunge-log.h
--- a/src/plugins/fts/fts-expunge-log.h	Wed Jan 21 01:46:13 2015 +0200
+++ b/src/plugins/fts/fts-expunge-log.h	Wed Jan 21 01:47:25 2015 +0200
@@ -18,6 +18,8 @@
 				 const guid_128_t mailbox_guid,
 				 uint32_t uid);
 int fts_expunge_log_append_commit(struct fts_expunge_log_append_ctx **ctx);
+/* Do not commit non-backed structures, abort them after use. */
+int fts_expunge_log_append_abort(struct fts_expunge_log_append_ctx **ctx);
 
 int fts_expunge_log_uid_count(struct fts_expunge_log *log,
 			      unsigned int *expunges_r);


More information about the dovecot-cvs mailing list