From 1f0b2dc243ce052e674b7672d496f7b14e29db6c Mon Sep 17 00:00:00 2001 From: Jan Radon Date: Fri, 23 Jun 2017 12:07:50 +0200 Subject: [PATCH] #40 Mtime mtime of copy is now set to original mails mtime. #41 guid is now std::String --- src/storage-rbox/rbox-copy.cpp | 2 ++ src/storage-rbox/rbox-mail.cpp | 18 ++++++++++++++---- src/storage-rbox/rbox-save.cpp | 33 ++++++++++++++++++--------------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/storage-rbox/rbox-copy.cpp b/src/storage-rbox/rbox-copy.cpp index 1377c5ce..9132a489 100644 --- a/src/storage-rbox/rbox-copy.cpp +++ b/src/storage-rbox/rbox-copy.cpp @@ -115,6 +115,8 @@ static int rbox_mail_storage_try_copy(struct mail_save_context **_ctx, struct ma i_debug("rbox_mail_storage_try_copy: source mail oid = %s", src_oid.c_str()); write_op.copy_from(src_oid, r_storage->s->get_io_ctx(), r_storage->s->get_io_ctx().get_last_version()); + write_op.mtime(&ctx->data.received_date); + ret_val = r_storage->s->get_io_ctx().operate(r_ctx->current_object->get_oid(), &write_op); } FUNC_END(); diff --git a/src/storage-rbox/rbox-mail.cpp b/src/storage-rbox/rbox-mail.cpp index 07db430b..011efa1e 100644 --- a/src/storage-rbox/rbox-mail.cpp +++ b/src/storage-rbox/rbox-mail.cpp @@ -109,8 +109,11 @@ static int rbox_mail_get_metadata(struct mail *_mail) { rmail->mail_object->set_state(attrset[RadosMailObject::X_ATTR_STATE].to_str()); rmail->mail_object->set_version(attrset[RadosMailObject::X_ATTR_VERSION].to_str()); - guid_128_t guid = {}; - attrset[RadosMailObject::X_ATTR_GUID].copy(0, sizeof(guid), reinterpret_cast(guid)); + guid_128_t guid; + if (guid_128_from_string(attrset[RadosMailObject::X_ATTR_GUID].to_str().c_str(), guid) < 0) { + FUNC_END_RET("ret == -1; value in X_ATTR_GUID guid invalid"); + return -1; + } rmail->mail_object->set_guid(guid); rmail->mail_object->set_pop3_uidl(attrset[RadosMailObject::X_ATTR_POP3_UIDL].to_str()); @@ -128,8 +131,6 @@ static int rbox_mail_get_metadata(struct mail *_mail) { FUNC_END_RET("ret == -1; value in X_ATTR_RECEIVED_DATE to long"); return -1; } - attrset[RadosMailObject::X_ATTR_RECEIVED_DATE].copy(0, length, reinterpret_cast(&received_date)); - rmail->mail_object->set_received_date(received_date); time_t send_date = 0; length = attrset[RadosMailObject::X_ATTR_SAVE_DATE].length(); @@ -139,6 +140,15 @@ static int rbox_mail_get_metadata(struct mail *_mail) { } attrset[RadosMailObject::X_ATTR_SAVE_DATE].copy(0, length, reinterpret_cast(&send_date)); rmail->mail_object->set_save_date(send_date); + uint64_t file_size = 0; + time_t received_date_rados; + + if (((r_storage->s)->get_io_ctx()).stat(rmail->mail_object->get_oid(), &file_size, &received_date_rados) < 0) { + FUNC_END_RET("ret == -1; cannot stat object to get received date and oid."); + return -1; + } + + rmail->mail_object->set_received_date(received_date_rados); FUNC_END(); return 0; diff --git a/src/storage-rbox/rbox-save.cpp b/src/storage-rbox/rbox-save.cpp index 54abac52..d3c08c84 100644 --- a/src/storage-rbox/rbox-save.cpp +++ b/src/storage-rbox/rbox-save.cpp @@ -193,10 +193,9 @@ static int rbox_save_mail_write_metadata(struct rbox_save_context *ctx) { { bufferlist bl; - bl.append((const char *)ctx->mail_guid, sizeof(ctx->mail_guid)); + bl.append(guid_128_to_string(ctx->mail_guid)); ctx->current_object->get_write_op().setxattr(RadosMailObject::X_ATTR_GUID.c_str(), bl); } - { bufferlist bl; bl.append(mdata->save_date); @@ -240,10 +239,14 @@ void clean_up_failed(struct rbox_save_context *_r_ctx) { // do some expunges mail_index_expunge(_r_ctx->trans, _r_ctx->seq); - // TOD(jrse) reenable it mail_cache_transaction_reset(_r_ctx->ctx.transaction->cache_trans); - _r_ctx->current_object->get_completion_private()->wait_for_complete(); - _r_ctx->current_object->get_write_op().remove(); - remove_from_rados(r_storage->s, _r_ctx->current_object->get_oid()); + int ret = r_storage->s->get_io_ctx().aio_flush_async(_r_ctx->current_object->get_completion_private().get()); + if (ret > 0) { + if (_r_ctx->current_object->get_completion_private()->get_return_value() >= 0) { + mail_cache_transaction_reset(_r_ctx->ctx.transaction->cache_trans); + _r_ctx->current_object->get_write_op().remove(); + remove_from_rados(r_storage->s, _r_ctx->current_object->get_oid()); + } + } _r_ctx->mail_count--; } @@ -272,23 +275,23 @@ int rbox_save_finish(struct mail_save_context *_ctx) { } if (!r_ctx->failed) { - rbox_save_mail_write_metadata(r_ctx); - ret = r_ctx->current_object->get_completion_private()->set_complete_callback( r_ctx->current_object, rbox_transaction_private_complete_callback); if (ret == 0) { if (r_ctx->copying != TRUE) { i_debug("copying is true "); + rbox_save_mail_write_metadata(r_ctx); librados::bufferlist mail_data_bl; mail_data_bl.append(str_c(r_ctx->mail_buffer)); r_ctx->current_object->get_write_op().write_full(mail_data_bl); + + // MAKE SYNC, ASYNC + ret = r_storage->s->get_io_ctx().aio_operate(r_ctx->current_object->get_oid(), + r_ctx->current_object->get_completion_private().get(), + &r_ctx->current_object->get_write_op()); } - // MAKE SYNC, ASYNC - ret = r_storage->s->get_io_ctx().aio_operate(r_ctx->current_object->get_oid(), - r_ctx->current_object->get_completion_private().get(), - &r_ctx->current_object->get_write_op()); - } - r_ctx->failed = ret < 0; + } + r_ctx->failed = ret < 0; } if (r_ctx->failed) { @@ -352,7 +355,7 @@ void rbox_transaction_save_commit_post(struct mail_save_context *_ctx, struct rbox_storage *r_storage = (struct rbox_storage *)&r_ctx->mbox->storage->storage; if (r_ctx->copying != TRUE) { - int ret = r_storage->s->get_io_ctx().aio_flush(); + int ret = r_storage->s->get_io_ctx().aio_flush_async(r_ctx->current_object->get_completion_private().get()); if (ret != 0) { r_ctx->failed = true; } else if (r_ctx->current_object->get_completion_private()->get_return_value() < 0) {