dovecot-2.0: dsync: Added -r option to make that sync side read-...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Oct 29 19:59:38 EET 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/e5bd42b8c2f0
changeset: 10226:e5bd42b8c2f0
user: Timo Sirainen <tss at iki.fi>
date: Thu Oct 29 13:59:11 2009 -0400
description:
dsync: Added -r option to make that sync side read-only.
diffstat:
5 files changed, 39 insertions(+), 11 deletions(-)
src/dsync/dsync-brain-msgs-new.c | 8 ++++++++
src/dsync/dsync-worker-private.h | 1 +
src/dsync/dsync-worker.c | 29 ++++++++++++++++++++---------
src/dsync/dsync-worker.h | 3 +++
src/dsync/dsync.c | 9 +++++++--
diffs (181 lines):
diff -r 67b88d1a12f2 -r e5bd42b8c2f0 src/dsync/dsync-brain-msgs-new.c
--- a/src/dsync/dsync-brain-msgs-new.c Wed Oct 28 21:20:46 2009 -0400
+++ b/src/dsync/dsync-brain-msgs-new.c Thu Oct 29 13:59:11 2009 -0400
@@ -26,11 +26,19 @@ static void msg_get_callback(enum dsync_
{
struct dsync_brain_msg_save_context *ctx = context;
struct istream *input;
+ const unsigned char *idata;
+ size_t size;
switch (result) {
case DSYNC_MSG_GET_RESULT_SUCCESS:
input = data->input;
dsync_worker_msg_save(ctx->iter->worker, ctx->msg, data);
+
+ /* if input is coming from proxy, we'll need to read the input
+ until EOF or we'll start treating the input as commands.
+ make sure saving read everything. */
+ while ((i_stream_read_data(input, &idata, &size, 0)) > 0)
+ i_stream_skip(input, size);
i_stream_unref(&input);
break;
case DSYNC_MSG_GET_RESULT_EXPUNGED:
diff -r 67b88d1a12f2 -r e5bd42b8c2f0 src/dsync/dsync-worker-private.h
--- a/src/dsync/dsync-worker-private.h Wed Oct 28 21:20:46 2009 -0400
+++ b/src/dsync/dsync-worker-private.h Thu Oct 29 13:59:11 2009 -0400
@@ -63,6 +63,7 @@ struct dsync_worker {
io_callback_t *input_callback, *output_callback;
void *input_context, *output_context;
+ unsigned int readonly:1;
unsigned int failed:1;
};
diff -r 67b88d1a12f2 -r e5bd42b8c2f0 src/dsync/dsync-worker.c
--- a/src/dsync/dsync-worker.c Wed Oct 28 21:20:46 2009 -0400
+++ b/src/dsync/dsync-worker.c Thu Oct 29 13:59:11 2009 -0400
@@ -9,6 +9,11 @@ void dsync_worker_deinit(struct dsync_wo
*_worker = NULL;
worker->v.deinit(worker);
+}
+
+void dsync_worker_set_readonly(struct dsync_worker *worker)
+{
+ worker->readonly = TRUE;
}
void dsync_worker_set_input_callback(struct dsync_worker *worker,
@@ -88,26 +93,30 @@ void dsync_worker_create_mailbox(struct
{
i_assert(dsync_box->uid_validity != 0 ||
mail_guid_128_is_empty(dsync_box->mailbox_guid.guid));
- worker->v.create_mailbox(worker, dsync_box);
+
+ if (!worker->readonly)
+ worker->v.create_mailbox(worker, dsync_box);
}
void dsync_worker_delete_mailbox(struct dsync_worker *worker,
const mailbox_guid_t *mailbox)
{
- worker->v.delete_mailbox(worker, mailbox);
+ if (!worker->readonly)
+ worker->v.delete_mailbox(worker, mailbox);
}
void dsync_worker_rename_mailbox(struct dsync_worker *worker,
const mailbox_guid_t *mailbox,
const char *name)
{
- worker->v.rename_mailbox(worker, mailbox, name);
+ if (!worker->readonly)
+ worker->v.rename_mailbox(worker, mailbox, name);
}
void dsync_worker_update_mailbox(struct dsync_worker *worker,
const struct dsync_mailbox *dsync_box)
{
- T_BEGIN {
+ if (!worker->readonly) T_BEGIN {
worker->v.update_mailbox(worker, dsync_box);
} T_END;
}
@@ -121,20 +130,20 @@ void dsync_worker_msg_update_metadata(st
void dsync_worker_msg_update_metadata(struct dsync_worker *worker,
const struct dsync_message *msg)
{
- if (!worker->failed)
+ if (!worker->failed && !worker->readonly)
worker->v.msg_update_metadata(worker, msg);
}
void dsync_worker_msg_update_uid(struct dsync_worker *worker,
uint32_t old_uid, uint32_t new_uid)
{
- if (!worker->failed)
+ if (!worker->failed && !worker->readonly)
worker->v.msg_update_uid(worker, old_uid, new_uid);
}
void dsync_worker_msg_expunge(struct dsync_worker *worker, uint32_t uid)
{
- if (!worker->failed)
+ if (!worker->failed && !worker->readonly)
worker->v.msg_expunge(worker, uid);
}
@@ -144,9 +153,11 @@ void dsync_worker_msg_copy(struct dsync_
dsync_worker_copy_callback_t *callback,
void *context)
{
- if (!worker->failed) {
+ if (!worker->failed && !worker->readonly) {
worker->v.msg_copy(worker, src_mailbox, src_uid, dest_msg,
callback, context);
+ } else {
+ callback(FALSE, context);
}
}
@@ -154,7 +165,7 @@ void dsync_worker_msg_save(struct dsync_
const struct dsync_message *msg,
const struct dsync_msg_static_data *data)
{
- if (!worker->failed)
+ if (!worker->failed && !worker->readonly)
worker->v.msg_save(worker, msg, data);
}
diff -r 67b88d1a12f2 -r e5bd42b8c2f0 src/dsync/dsync-worker.h
--- a/src/dsync/dsync-worker.h Wed Oct 28 21:20:46 2009 -0400
+++ b/src/dsync/dsync-worker.h Thu Oct 29 13:59:11 2009 -0400
@@ -19,6 +19,9 @@ struct dsync_worker *dsync_worker_init_l
struct dsync_worker *dsync_worker_init_local(struct mail_user *user);
struct dsync_worker *dsync_worker_init_proxy_client(int fd_in, int fd_out);
void dsync_worker_deinit(struct dsync_worker **worker);
+
+/* Set this worker as read-only. All attempted changes are ignored. */
+void dsync_worker_set_readonly(struct dsync_worker *worker);
/* If any function returns with "waiting for more data", the given callback
gets called when more data is available. */
diff -r 67b88d1a12f2 -r e5bd42b8c2f0 src/dsync/dsync.c
--- a/src/dsync/dsync.c Wed Oct 28 21:20:46 2009 -0400
+++ b/src/dsync/dsync.c Thu Oct 29 13:59:11 2009 -0400
@@ -75,13 +75,13 @@ int main(int argc, char *argv[])
struct mail_user *mail_user;
struct dsync_worker *worker1, *worker2;
const char *error, *username, *mailbox = NULL, *cmd = NULL;
- bool dest = TRUE;
+ bool dest = TRUE, readonly = FALSE;
int c, ret, fd_in = STDIN_FILENO, fd_out = STDOUT_FILENO;
master_service = master_service_init("dsync",
MASTER_SERVICE_FLAG_STANDALONE |
MASTER_SERVICE_FLAG_STD_CLIENT,
- &argc, &argv, "b:e:fu:v");
+ &argc, &argv, "b:e:fru:v");
username = getenv("USER");
while ((c = master_getopt(master_service)) > 0) {
@@ -93,6 +93,9 @@ int main(int argc, char *argv[])
break;
case 'e':
cmd = optarg;
+ break;
+ case 'r':
+ readonly = TRUE;
break;
case 'f':
brain_flags |= DSYNC_BRAIN_FLAG_FULL_SYNC;
@@ -130,6 +133,8 @@ int main(int argc, char *argv[])
}
worker1 = dsync_worker_init_local(mail_user);
+ if (readonly)
+ dsync_worker_set_readonly(worker1);
if (dest) {
i_set_failure_prefix(t_strdup_printf("dsync-dest(%s): ",
username));
More information about the dovecot-cvs
mailing list