maildir-copy.c revision 677e22747b82bf15b339e31d1d0106d62bf806da
/* Copyright (C) 2002-2004 Timo Sirainen */
#include "lib.h"
#include "array.h"
#include "ioloop.h"
#include "str.h"
#include "maildir-storage.h"
#include "maildir-uidlist.h"
#include "maildir-keywords.h"
#include "index-mail.h"
#include "mail-copy.h"
#include <stdlib.h>
#include <unistd.h>
struct hardlink_ctx {
const char *dest_fname;
unsigned int base_end_pos;
unsigned int size_set:1;
unsigned int success:1;
};
struct hardlink_ctx *ctx)
{
&size)) {
return 0;
"stat(%s) failed: %m", path);
return -1;
}
}
return 1;
}
void *context)
{
int ret;
return ret;
}
return 0;
"Not enough disk space");
return -1;
}
return 1;
"link(%s, %s) failed: %m",
return -1;
}
return 1;
}
static int
{
struct maildir_mailbox *dest_mbox =
struct maildir_mailbox *src_mbox =
struct maildir_save_context *ctx;
struct hardlink_ctx do_ctx;
t->save_ctx = maildir_save_transaction_init(t);
/* don't allow caller to specify recent flag */
flags &= ~MAIL_RECENT;
flags |= MAIL_RECENT;
/* the generated filename is _always_ unique, so we don't bother
trying to check if it already exists */
/* no keywords, hardlink directly to destination */
if (flags == MAIL_RECENT) {
} else {
}
} else {
/* keywords, hardlink to tmp/ with basename and later when we
}
return -1;
/* couldn't copy with hardlinking, fallback to copying */
return 0;
}
/* hardlinked to destination, set hardlinked-flag */
} else {
/* hardlinked to tmp/, treat as normal copied mail */
}
return 1;
}
{
struct maildir_transaction_context *t =
(struct maildir_transaction_context *)_t;
int ret;
t_push();
t_pop();
if (ret > 0)
return 0;
if (ret < 0)
return -1;
/* non-fatal hardlinking failure, try the slow way */
}
}