Skip to content

Commit

Permalink
#55 move/copy command.
Browse files Browse the repository at this point in the history
 
 fixed save_date issue. (save_date not set when moving mails with
doveadm move) save_date of moved file is set to time(null)
  • Loading branch information
jrse committed Jul 18, 2017
1 parent f7112fa commit 9612cc2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
22 changes: 18 additions & 4 deletions src/storage-rbox/rbox-copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern "C" {
#include "rbox-mail.h"
#include "rbox-save.h"
#include "rbox-storage-struct.h"
#include <time.h>

int rbox_mail_storage_copy(struct mail_save_context *ctx, struct mail *mail);

Expand Down Expand Up @@ -87,9 +88,9 @@ static int rbox_mail_storage_try_copy(struct mail_save_context **_ctx, struct ma
struct rbox_save_context *r_ctx = (struct rbox_save_context *)ctx;
struct rbox_storage *r_storage = (struct rbox_storage *)&r_ctx->mbox->storage->storage;
struct rbox_mail *rmail = (struct rbox_mail *)mail;
librados::IoCtx src_io_ctx;

librados::IoCtx dest_io_ctx = r_storage->s->get_io_ctx();
librados::IoCtx src_io_ctx;
const char *ns_src_mail = mail->box->list->ns->owner != nullptr ? mail->box->list->ns->owner->username : "";
const char *ns_dest_mail =
ctx->dest_mail->box->list->ns->owner != nullptr ? ctx->dest_mail->box->list->ns->owner->username : "";
Expand Down Expand Up @@ -119,19 +120,32 @@ static int rbox_mail_storage_try_copy(struct mail_save_context **_ctx, struct ma
std::string src_oid = rmail->mail_object->get_oid();
std::string dest_oid = r_ctx->current_object->get_oid();
i_debug("rbox_mail_storage_try_copy: from source %s to dest %s", src_oid.c_str(), dest_oid.c_str());
librados::ObjectWriteOperation write_op;

if (strcmp(ns_src_mail, ns_dest_mail) != 0) {
src_io_ctx.dup(dest_io_ctx);
src_io_ctx.set_namespace(ns_src_mail);
dest_io_ctx.set_namespace(ns_dest_mail);

} else {
src_io_ctx = dest_io_ctx;
}

librados::ObjectWriteOperation write_op;
i_debug("ns_compare: %s %s", ns_src_mail, ns_dest_mail);
write_op.copy_from(src_oid, src_io_ctx, src_io_ctx.get_last_version());
write_op.mtime(&ctx->data.received_date);
time_t now = time(NULL);


// because we create a copy, save date needs to be updated
// as an alternative we could use &ctx->data.save_date here if we save it to xattribute in write_metadata
// and restore it in read_metadata function. => save_date of copy/move will be same as source.
// write_op.mtime(&ctx->data.save_date);

write_op.mtime(NULL);

i_debug("cpy_time: oid: %s , save_date: %s", src_oid.c_str(), std::ctime(&rmail->imail.data.save_date));

ret_val = dest_io_ctx.operate(dest_oid, &write_op);
i_debug("copy failed: %s , ret_val = %d , mtime %ld", src_oid.c_str(), ret_val, &ctx->data.save_date);

// reset io_ctx
dest_io_ctx.set_namespace(ns_src_mail);
Expand Down
14 changes: 6 additions & 8 deletions src/storage-rbox/rbox-save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string>
#include <map>
#include <vector>

#include <time.h>
#include <rados/librados.hpp>

extern "C" {
Expand Down Expand Up @@ -231,7 +231,7 @@ int rbox_save_mail_write_metadata(struct rbox_save_context *ctx, librados::Objec
write_op_xattr->setxattr(key.c_str(), bl);
}
}

i_debug("save_date %s", std::ctime(&mdata->save_date));
write_op_xattr->mtime(&mdata->save_date);

FUNC_END();
Expand Down Expand Up @@ -347,14 +347,12 @@ int rbox_save_finish(struct mail_save_context *_ctx) {
int ret = 0;

r_ctx->finished = TRUE;
if (_ctx->data.save_date != (time_t)-1) {
struct index_mail *mail = (struct index_mail *)_ctx->dest_mail;

uint32_t t = _ctx->data.save_date;
index_mail_cache_add(mail, MAIL_CACHE_SAVE_DATE, &t, sizeof(t));
} else {
if (_ctx->data.save_date == (time_t)-1) {
_ctx->data.save_date = time(NULL);
}
uint32_t save_date = _ctx->data.save_date;
index_mail_cache_add((struct index_mail *)_ctx->dest_mail, MAIL_CACHE_SAVE_DATE, &save_date, sizeof(save_date));
i_debug("oid: %s , save_date: %s", r_ctx->current_object->get_oid().c_str(), std::ctime(&_ctx->data.save_date));

if (!r_ctx->failed) {
if (ret == 0) {
Expand Down

0 comments on commit 9612cc2

Please sign in to comment.