mail-index-open.c revision 1cfc39f5c151f51b554811336baede97c5a82c02
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "ioloop.h"
#include "file-lock.h"
#include "file-set-size.h"
#include "hostpid.h"
#include "mmap-util.h"
#include "unlink-lockfiles.h"
#include "write-full.h"
#include "mail-index.h"
#include "mail-index-data.h"
#include "mail-index-util.h"
#include "mail-tree.h"
#include "mail-lockdir.h"
#include "mail-modifylog.h"
#include "mail-custom-flags.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
static const char *index_file_prefixes[] =
static int delete_index(const char *path)
{
char tmp[1024];
int i;
/* main index */
return FALSE;
for (i = 0; index_file_prefixes[i] != NULL; i++) {
path, index_file_prefixes[i]);
return FALSE;
i++;
}
return TRUE;
}
int check_version)
{
/* read the header */
return FALSE;
return FALSE;
/* check the compatibility */
}
/* Returns TRUE if we're compatible with given index file. May delete the
file if it's from older version. */
{
int fd, compatible;
if (fd == -1) {
return FALSE;
}
/* version mismatch */
compatible = FALSE;
/* of older version, we don't need it anymore */
(void)delete_index(path);
}
}
return compatible;
}
/* Returns a file name of compatible index */
{
const char *name;
char path[1024];
hostpid_init();
/* first try .imap.index-<hostname> */
return name;
/* then try the generic .imap.index */
return name;
return NULL;
}
{
/* update \Recent message counters */
/* keep last_recent_uid to next_uid-1 */
return FALSE;
}
return FALSE;
} else {
}
/* UID values are getting too high, rebuild index */
}
/* finally reset the modify log marks, fsck or syncing might
have deleted some messages, and since we're only just
opening the index, there's no need to remember them */
return FALSE;
}
return TRUE;
}
{
int rebuild;
if (!mail_index_mmap_update(index))
return FALSE;
if (!mail_index_data_open(index)) {
return FALSE;
/* data file is corrupted, need to rebuild index */
if (!mail_index_data_create(index))
return FALSE;
}
/* custom flags file needs to be open before
rebuilding index */
return FALSE;
/* index is corrupted, rebuild */
return FALSE;
/* no inconsistency problems while still opening
the index */
}
if (!mail_tree_open_or_create(index))
return FALSE;
return FALSE;
/* index needs fscking */
return FALSE;
}
/* remove deleted blocks from index file */
if (!mail_index_compress(index))
return FALSE;
}
return FALSE;
}
/* sync before updating cached fields so it won't print
warnings if mails were deleted */
return FALSE;
/* need to update cached fields */
if (!mail_index_update_cache(index))
return FALSE;
}
/* remove unused space from index data file.
keep after cache_fields which may move data
and create unused space.. */
if (!mail_index_compress_data(index))
return FALSE;
}
return FALSE;
return FALSE;
return TRUE;
}
int update_recent, int fast)
{
int fd;
/* the index file should already be checked that it exists and
we're compatible with it. */
if (fd == -1)
/* if index is being created, we'll wait here until it's finished */
return FALSE;
}
/* check the compatibility anyway just to be sure */
return FALSE;
}
return FALSE;
}
return FALSE;
}
return TRUE;
}
const char **index_path)
{
*index_path = NULL;
return FALSE;
}
fsize = sizeof(MailIndexHeader) +
INDEX_MIN_RECORDS_COUNT * sizeof(MailIndexRecord);
return FALSE;
}
return FALSE;
}
/* move the temp index into the real one. we also need to figure
out what to call ourself on the way. */
/* doesn't really matter, log anyway */
}
} else {
/* fatal error */
path, *index_path);
return FALSE;
}
/* don't try to support different architectures,
just overwrite the index if it's already there. */
} else {
/* fallback to .imap.index-hostname - we require each
system to have a different hostname so it's safe to
override previous index as well */
hostpid_init();
my_hostname, NULL);
}
path, *index_path);
return FALSE;
}
}
return TRUE;
}
int update_recent)
{
const char *path, *index_path;
int fd;
*dir_unlocked = FALSE;
index_path = NULL;
if (index->nodiskspace) {
/* don't even bother trying to create it */
fd = -1;
} else {
/* first create the index into temporary file. */
if (fd != -1) {
path, &index_path)) {
fd = -1;
}
}
/* fatal failure */
return FALSE;
}
}
if (fd == -1) {
/* no space for index files, keep it in memory */
} else {
}
/* the fd is actually already locked, now we're just making it
clear to the indexing code. */
return FALSE;
}
/* it's not good to keep the directory locked too long. our index file
is locked which is enough. */
*dir_unlocked = TRUE;
do {
break;
if (!mail_index_data_create(index))
break;
/* we're out of disk space, keep it in
memory this time */
}
break;
}
if (!mail_tree_create(index))
break;
if (!mail_modifylog_create(index))
break;
break;
break;
return TRUE;
} while (0);
return FALSE;
}
{
/* mark the index requiring rebuild - rebuild() removes this flag
when it succeeds */
/* set the fields we always want to cache */
}
static void mail_index_cleanup_temp_files(const char *dir)
{
}
{
/* this isn't initialized anywhere else */
return FALSE;
return FALSE;
return TRUE;
}
{
int failed, dir_unlocked;
return TRUE;
/* index wasn't found or it was broken. lock the directory and check
again, just to make sure we don't end up having two index files
due to race condition with another process. */
return FALSE;
} else {
}
return FALSE;
if (failed)
return FALSE;
return TRUE;
}