dovecot-2.1: mdbox: Allow reflink-copying a mail when wanted GUI...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jan 9 05:35:35 EET 2013


details:   http://hg.dovecot.org/dovecot-2.1/rev/df06c834d7e8
changeset: 14877:df06c834d7e8
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jan 09 05:35:20 2013 +0200
description:
mdbox: Allow reflink-copying a mail when wanted GUID matches the current GUID.

diffstat:

 src/lib-storage/index/dbox-multi/mdbox-save.c |  28 ++++++++++++++++++--------
 1 files changed, 19 insertions(+), 9 deletions(-)

diffs (57 lines):

diff -r b87a7c4d775f -r df06c834d7e8 src/lib-storage/index/dbox-multi/mdbox-save.c
--- a/src/lib-storage/index/dbox-multi/mdbox-save.c	Wed Jan 09 05:33:32 2013 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-save.c	Wed Jan 09 05:35:20 2013 +0200
@@ -412,14 +412,14 @@
 	struct dbox_save_mail *save_mail;
 	struct mdbox_mailbox *src_mbox;
 	struct mdbox_mail_index_record rec;
-	const void *data;
+	const void *guid_data;
+	guid_128_t wanted_guid;
 	bool expunged;
 
 	ctx->ctx.finished = TRUE;
 
 	if (mail->box->storage != _ctx->transaction->box->storage ||
-	    _ctx->transaction->box->disable_reflink_copy_to ||
-	    _ctx->guid != NULL)
+	    _ctx->transaction->box->disable_reflink_copy_to)
 		return mail_storage_copy(_ctx, mail);
 	src_mbox = (struct mdbox_mailbox *)mail->box;
 
@@ -429,6 +429,20 @@
 			      &rec.map_uid) < 0)
 		return -1;
 
+	mail_index_lookup_ext(mail->transaction->view, mail->seq,
+			      src_mbox->guid_ext_id, &guid_data, &expunged);
+	if (guid_data == NULL || guid_128_is_empty(guid_data)) {
+		/* missing GUID, something's broken. don't copy using
+		   refcounting. */
+		return mail_storage_copy(_ctx, mail);
+	} else if (_ctx->guid != NULL &&
+		   (guid_128_from_string(_ctx->guid, wanted_guid) < 0 ||
+		    memcmp(guid_data, wanted_guid, sizeof(wanted_guid)) != 0)) {
+		/* GUID change requested. we can't do it with refcount
+		   copying */
+		return mail_storage_copy(_ctx, mail);
+	}
+
 	/* remember the map_uid so we can later increase its refcount */
 	if (!array_is_created(&ctx->copy_map_uids))
 		i_array_init(&ctx->copy_map_uids, 32);
@@ -439,12 +453,8 @@
 	mail_index_update_ext(ctx->ctx.trans, ctx->ctx.seq,
 			      ctx->mbox->ext_id, &rec, NULL);
 
-	mail_index_lookup_ext(mail->transaction->view, mail->seq,
-			      src_mbox->guid_ext_id, &data, &expunged);
-	if (data != NULL) {
-		mail_index_update_ext(ctx->ctx.trans, ctx->ctx.seq,
-				      ctx->mbox->guid_ext_id, data, NULL);
-	}
+	mail_index_update_ext(ctx->ctx.trans, ctx->ctx.seq,
+			      ctx->mbox->guid_ext_id, guid_data, NULL);
 	index_copy_cache_fields(_ctx, mail, ctx->ctx.seq);
 
 	save_mail = array_append_space(&ctx->mails);


More information about the dovecot-cvs mailing list