Mercurial > dovecot > core-2.2
changeset 18694:9ad3f11617f1
sdbox: When hardlink-copying a mail in alt storage, keep it within the alt storage.
Also make sure that the alt-flag is set correctly no matter where we copy
the mail.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 15 May 2015 11:15:50 +0300 |
parents | 91bbd6753689 |
children | 46969c4cc57e |
files | src/lib-storage/index/dbox-single/sdbox-copy.c src/lib-storage/index/dbox-single/sdbox-file.c |
diffstat | 2 files changed, 18 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-single/sdbox-copy.c Thu May 14 23:49:12 2015 +0300 +++ b/src/lib-storage/index/dbox-single/sdbox-copy.c Fri May 15 11:15:50 2015 +0300 @@ -89,7 +89,7 @@ (struct sdbox_mailbox *)_ctx->transaction->box; struct sdbox_mailbox *src_mbox; struct dbox_file *src_file, *dest_file; - const char *src_path; + const char *src_path, *dest_path; int ret; if (strcmp(mail->box->storage->name, SDBOX_STORAGE_NAME) == 0) @@ -102,11 +102,18 @@ src_file = sdbox_file_init(src_mbox, mail->uid); dest_file = sdbox_file_init(dest_mbox, 0); + ctx->ctx.data.flags &= ~DBOX_INDEX_FLAG_ALT; + src_path = src_file->primary_path; - ret = nfs_safe_link(src_path, dest_file->cur_path, FALSE); + dest_path = dest_file->primary_path; + ret = nfs_safe_link(src_path, dest_path, FALSE); if (ret < 0 && errno == ENOENT && src_file->alt_path != NULL) { src_path = src_file->alt_path; - ret = nfs_safe_link(src_path, dest_file->cur_path, FALSE); + if (dest_file->alt_path != NULL) { + dest_path = dest_file->cur_path = dest_file->alt_path; + ctx->ctx.data.flags |= DBOX_INDEX_FLAG_ALT; + } + ret = nfs_safe_link(src_path, dest_path, FALSE); } if (ret < 0) { if (ECANTLINK(errno)) @@ -119,8 +126,7 @@ } else { mail_storage_set_critical( _ctx->transaction->box->storage, - "link(%s, %s) failed: %m", - src_path, dest_file->cur_path); + "link(%s, %s) failed: %m", src_path, dest_path); } dbox_file_unref(&src_file); dbox_file_unref(&dest_file);
--- a/src/lib-storage/index/dbox-single/sdbox-file.c Thu May 14 23:49:12 2015 +0300 +++ b/src/lib-storage/index/dbox-single/sdbox-file.c Fri May 15 11:15:50 2015 +0300 @@ -44,10 +44,7 @@ sdbox_file_init_paths(file, fname); file->uid = uid; } else { - file->file.primary_path = - i_strdup_printf("%s/%s", - mailbox_get_path(&mbox->box), - dbox_generate_tmp_filename()); + sdbox_file_init_paths(file, dbox_generate_tmp_filename()); } } T_END; dbox_file_init(&file->file); @@ -151,16 +148,19 @@ int sdbox_file_assign_uid(struct sdbox_file *file, uint32_t uid) { - const char *old_path, *new_fname, *new_path; + const char *p, *old_path, *dir, *new_fname, *new_path; struct stat st; i_assert(file->uid == 0); i_assert(uid != 0); old_path = file->file.cur_path; + p = strrchr(old_path, '/'); + i_assert(p != NULL); + dir = t_strdup_until(old_path, p); + new_fname = t_strdup_printf(SDBOX_MAIL_FILE_FORMAT, uid); - new_path = t_strdup_printf("%s/%s", mailbox_get_path(&file->mbox->box), - new_fname); + new_path = t_strdup_printf("%s/%s", dir, new_fname); if (stat(new_path, &st) == 0) { mail_storage_set_critical(&file->file.storage->storage,