Mercurial > dovecot > original-hg > dovecot-1.2
changeset 333:fad3998041d4 HEAD
hardlink-COPY fixed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 30 Sep 2002 01:08:29 +0300 |
parents | aeff4a271544 |
children | e34e14d758eb |
files | src/lib-storage/index/maildir/maildir-copy.c |
diffstat | 1 files changed, 25 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-copy.c Sun Sep 29 21:01:25 2002 +0300 +++ b/src/lib-storage/index/maildir/maildir-copy.c Mon Sep 30 01:08:29 2002 +0300 @@ -2,15 +2,18 @@ #include "lib.h" #include "index-messageset.h" +#include "maildir-index.h" #include "maildir-storage.h" +#include "mail-custom-flags.h" #include <stdlib.h> #include <unistd.h> typedef struct { MailStorage *storage; - const char *dest_maildir; + IndexMailbox *dest; int error; + const char **custom_flags; } CopyHardContext; static int copy_hard_func(MailIndex *index, MailIndexRecord *rec, @@ -18,16 +21,22 @@ unsigned int idx_seq __attr_unused__, void *context) { CopyHardContext *ctx = context; + MailFlags flags; const char *fname; char src[1024], dest[1024]; - /* FIXME: this is buggy */ - if (1) return FALSE; + flags = rec->msg_flags; + if (!index_mailbox_fix_custom_flags(ctx->dest, &flags, + ctx->custom_flags)) + return FALSE; /* link the file */ fname = index->lookup_field(index, rec, FIELD_TYPE_LOCATION); i_snprintf(src, sizeof(src), "%s/cur/%s", index->dir, fname); - i_snprintf(dest, sizeof(dest), "%s/new/%s", ctx->dest_maildir, fname); + + fname = maildir_filename_set_flags(fname, flags); + i_snprintf(dest, sizeof(dest), "%s/new/%s", + ctx->dest->index->dir, fname); if (link(src, dest) == 0) return TRUE; @@ -59,21 +68,20 @@ } ctx.storage = src->box.storage; - ctx.dest_maildir = dest->index->dir; + ctx.dest = dest; ctx.error = FALSE; + ctx.custom_flags = mail_custom_flags_list_get(src->index->custom_flags); ret = index_messageset_foreach(src, messageset, uidset, - copy_hard_func, &ctx) <= 0; + copy_hard_func, &ctx); - if (!dest->index->set_lock(dest->index, MAIL_LOCK_UNLOCK)) { + mail_custom_flags_list_unref(src->index->custom_flags); + + if (!dest->index->set_lock(dest->index, MAIL_LOCK_UNLOCK)) mail_storage_set_index_error(dest); - ret = -1; - } - if (!src->index->set_lock(src->index, MAIL_LOCK_SHARED)) { + if (!src->index->set_lock(src->index, MAIL_LOCK_UNLOCK)) mail_storage_set_index_error(src); - ret = -1; - } return ctx.error ? -1 : ret; } @@ -95,14 +103,14 @@ copy_with_hardlinks option is on, do it */ switch (maildir_copy_with_hardlinks(ibox, (IndexMailbox *) destbox, messageset, uidset)) { - case -1: - case -2: - return FALSE; case 1: return TRUE; + case 0: + /* non-fatal hardlinking failure, try the slow way */ + break; + default: + return FALSE; } - - /* non-fatal hardlinking failure, try the slow way */ } return index_storage_copy(box, destbox, messageset, uidset);