Skip to content

Commit

Permalink
#40 Mtime
Browse files Browse the repository at this point in the history
  mtime of copy is now set to original mails mtime.
#41 guid is now std::String
  • Loading branch information
jrse committed Jun 23, 2017
1 parent 5ec9745 commit 8bf84be
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/storage-rbox/rbox-copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 14 additions & 4 deletions src/storage-rbox/rbox-mail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(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());
Expand All @@ -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<char *>(&received_date));
rmail->mail_object->set_received_date(received_date);

time_t send_date = 0;
length = attrset[RadosMailObject::X_ATTR_SAVE_DATE].length();
Expand All @@ -139,6 +140,15 @@ static int rbox_mail_get_metadata(struct mail *_mail) {
}
attrset[RadosMailObject::X_ATTR_SAVE_DATE].copy(0, length, reinterpret_cast<char *>(&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;
Expand Down
33 changes: 18 additions & 15 deletions src/storage-rbox/rbox-save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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--;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8bf84be

Please sign in to comment.