cydir-storage.c revision 2dd39e478269d6fb0bb26d12b394aa30ee965e38
/* Copyright (C) 2007 Timo Sirainen */
#include "lib.h"
#include "array.h"
#include "ioloop.h"
#include "str.h"
#include "mkdir-parents.h"
#include "unlink-directory.h"
#include "index-mail.h"
#include "mail-copy.h"
#include "cydir-sync.h"
#include "cydir-storage.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#define CYDIR_LIST_CONTEXT(obj) \
extern struct mail_storage cydir_storage;
extern struct mailbox cydir_mailbox;
static int
enum mailbox_list_file_type type,
enum mailbox_info_flags *flags);
static int
const char **error_r)
{
const char *p;
/* we won't do any guessing for this format. */
if (debug)
i_info("cydir: mailbox location not given");
*error_r = "Root mail directory not given";
return -1;
}
/* <root dir> [:INDEX=<dir>] */
if (debug)
if (p == NULL)
else {
do {
p++;
p = strchr(p, ':');
} while (p != NULL);
}
/* strip trailing '/' */
return 0;
}
static struct mail_storage *cydir_alloc(void)
{
struct cydir_storage *storage;
}
const char **error_r)
{
struct mailbox_list_settings list_set;
error_r) < 0)
return -1;
"stat(%s) failed: %m",
} else {
"Root mail directory doesn't exist: %s",
}
return -1;
}
} else {
return -1;
}
}
return -1;
return 0;
}
{
if (!mail_storage_set_error_from_errno(storage)) {
"mkdir(%s) failed: %m", path);
}
return -1;
}
return 0;
}
static struct mailbox *
enum mailbox_open_flags flags)
{
struct cydir_mailbox *mbox;
struct mail_index *index;
const char *path;
return NULL;
}
static struct mailbox *
{
const char *path;
"cydir doesn't support streamed mailboxes");
return NULL;
}
return NULL;
} else {
path);
return NULL;
}
}
const char *name,
bool directory __attr_unused__)
{
const char *path;
"Mailbox already exists");
return -1;
}
}
static int
const char *name)
{
struct dirent *d;
unsigned int dir_len;
bool unlinked_something = FALSE;
if (!mailbox_list_set_error_from_errno(list)) {
"opendir(%s) failed: %m", path);
}
return -1;
}
errno = 0;
if (d->d_name[0] == '.') {
/* skip . and .. */
continue;
continue;
}
/* trying to unlink() a directory gives either EPERM or EISDIR
(non-POSIX). it doesn't really work anywhere in practise,
so don't bother stat()ing the file first */
"unlink_directory(%s) failed: %m",
}
}
path);
}
return -1;
}
if (!unlinked_something) {
t_strdup_printf("Directory %s isn't empty, "
"can't delete it.", name));
return -1;
}
return 0;
}
static int
{
const char *src;
/* Make sure the indexes are closed before trying to delete the
directory that contains them. It can still fail with some NFS
implementations if indexes are opened by another session, but
that can't really be helped. */
/* delete the index and control directories */
return -1;
/* check if the mailbox actually exists */
return -1;
}
}
{
else
}
enum mailbox_list_file_type type,
enum mailbox_info_flags *flags)
{
const char *mail_path;
int ret = 1;
return 0;
}
/* try to avoid stat() with these checks */
if (type != MAILBOX_LIST_FILE_TYPE_DIR &&
/* it's a file */
return 0;
}
/* need to stat() then */
t_push();
/* non-directory */
ret = 0;
}
} else {
/* non-selectable, but may contain subdirs */
*flags |= MAILBOX_NOSELECT;
}
t_pop();
return ret;
}
static void cydir_class_init(void)
{
}
static void cydir_class_deinit(void)
{
}
struct mail_storage cydir_storage = {
{
NULL,
NULL,
}
};
struct mailbox cydir_mailbox = {
{
NULL,
}
};