convert-storage.c revision 5bdad39213d28ab35e615a7f4ea1712ab25b6a80
/* Copyright (c) 2006-2007 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "file-lock.h"
#include "file-dotlock.h"
#include "mail-storage-private.h"
#include "mail-namespace.h"
#include "mail-search.h"
#include "convert-storage.h"
#include <stdio.h>
#include <dirent.h>
#define CONVERT_LOCK_FILENAME ".dovecot.convert"
struct dotlock_settings dotlock_settings = {
};
{
struct mail_search_context *ctx;
struct mail_search_arg search_arg;
int ret = 0;
return -1;
struct mail_keywords *keywords;
const char *const *keywords_list;
/* touch the lock file so that if there are tons of
mails another process won't override our lock. */
(void)file_dotlock_touch(dotlock);
}
if (ret < 0)
break;
}
if (mailbox_search_deinit(&ctx) < 0)
ret = -1;
if (ret < 0)
else
/* source transaction committing isn't all that important.
ignore if it fails. */
if (ret < 0)
else
(void)mailbox_transaction_commit(&src_trans);
return ret;
}
{
enum mail_error error;
}
static const char *
struct mail_storage *source_storage,
{
return name;
for (p = dest_name; *p != '\0'; p++) {
if (*p == dest_sep)
*p = set->alt_hierarchy_char;
else if (*p == src_sep)
*p = dest_sep;
}
return dest_name;
}
struct mail_storage *dest_storage,
const char *src_name,
const char *dest_name)
{
static const char *maildir_files[] = {
"dovecot-uidlist",
"dovecot-keywords",
"dovecot.index",
"dovecot.index.log",
"dovecot.index.cache"
};
unsigned int i, src_dir_len, dest_dir_len;
bool t;
int ret;
/* rename cur/ directory as the destination directory */
return -1;
}
/* move metadata files */
for (i = 0; i < N_ELEMENTS(maildir_files); i++) {
i_error("rename(%s, %s) failed: %m",
}
}
/* move files in new/ */
return 0;
return -1;
}
ret = 0;
errno = 0;
continue;
i_error("rename(%s, %s) failed: %m",
ret = -1;
errno = 0;
}
}
if (errno != 0) {
ret = -1;
}
ret = -1;
}
return ret;
}
struct mail_storage *dest_storage,
const struct mailbox_info *info,
const struct convert_settings *set)
{
int ret = 0;
return 0;
/* \NoSelect mailbox, so it's probably a "directory" */
return 0;
TRUE) < 0) {
i_error("Mailbox conversion: Couldn't create mailbox "
"directory %s", dest_name);
return -1;
}
return 0;
}
i_error("Mailbox conversion failed for mailbox %s",
name);
return -1;
}
return 0;
}
/* First open the source mailbox. If we can't open it, don't create
the destination mailbox either. */
if (set->skip_broken_mailboxes)
return 0;
i_error("Mailbox conversion: "
"Couldn't open source mailbox %s: %s",
return -1;
}
/* Create and open the destination mailbox. */
FALSE) < 0) {
i_error("Mailbox conversion: "
"Couldn't create mailbox %s: %s",
return -1;
}
}
i_error("Mailbox conversion: Couldn't open dest mailbox %s: %s",
return -1;
}
i_error("Mailbox conversion: Couldn't copy mailbox %s: %s",
}
return ret;
}
struct mail_storage *dest_storage,
const struct convert_settings *set)
{
struct mailbox_list_iterate_context *iter;
const struct mailbox_info *info;
int ret = 0;
t_push();
t_pop();
if (ret < 0)
break;
/* In case there are lots of mailboxes. Also the other touch
is done only after 100 mails. */
(void)file_dotlock_touch(dotlock);
}
if (mailbox_list_iter_deinit(&iter) < 0)
ret = -1;
return ret;
}
struct mail_storage *dest_storage,
const struct convert_settings *set)
{
struct mailbox_list_iterate_context *iter;
const struct mailbox_info *info;
struct mailbox_list *dest_list;
const char *dest_name;
int ret = 0;
TRUE) < 0) {
ret = -1;
break;
}
}
if (mailbox_list_iter_deinit(&iter) < 0)
ret = -1;
return ret;
}
const struct convert_settings *set)
{
enum file_lock_method lock_method;
int ret;
/* No need for conversion. */
return 0;
}
/* If home directory doesn't exist, creating the destination storage
will most likely create it. So do this before locking. */
i_error("Mailbox conversion: Failed to create destination "
return -1;
}
if (ret <= 0) {
if (ret == 0)
i_error("Mailbox conversion: Lock creation timeouted");
else
return -1;
}
/* just in case if another process just had converted the mailbox,
reopen the source storage */
/* No need for conversion anymore. */
return 0;
}
if (ret == 0) {
}
if (ret == 0) {
/* all finished. rename the source directory to mark the
move as finished. */
bool is_file;
&is_file);
i_error("Mailbox conversion: "
/* return success anyway */
}
}
ret = 1;
}
return ret;
}