mail-index-open.c revision c29c4813481f479b5544489b5451c8761e21ef13
/* Copyright (C) 2002-2003 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-modifylog.h"
#include "mail-custom-flags.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
enum mail_index_open_flags flags)
{
struct mail_index_header *hdr;
/* update \Recent message counters */
if ((flags & MAIL_INDEX_OPEN_FLAG_UPDATE_RECENT) != 0 &&
/* 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;
}
enum mail_index_open_flags flags)
{
int rebuilt;
if ((flags & _MAIL_INDEX_OPEN_FLAG_CREATING) == 0) {
if (!mail_index_data_open(index)) {
return FALSE;
/* data file is corrupted, need to rebuild index */
}
}
if ((flags & _MAIL_INDEX_OPEN_FLAG_CREATING) != 0) {
return FALSE;
if (!mail_index_data_create(index))
return FALSE;
}
/* custom flags file needs to be open before
rebuilding index */
return FALSE;
if ((flags & _MAIL_INDEX_OPEN_FLAG_CREATING) != 0 ||
return FALSE;
/* no inconsistency problems since we're still opening
the index */
} else {
}
if ((flags & _MAIL_INDEX_OPEN_FLAG_CREATING) == 0) {
if (!mail_tree_open_or_create(index))
return FALSE;
return FALSE;
} else {
if (!mail_tree_create(index))
return FALSE;
if (!mail_modifylog_create(index))
return FALSE;
}
/* index needs fscking */
return FALSE;
}
return FALSE;
}
if (!rebuilt) {
/* sync ourself. do it before updating cache and compression
which may happen because of this. */
!index->nodiskspace)
return FALSE;
}
/* we never want to keep shared lock if syncing happens to set it.
either exclusive or nothing (NOTE: drop it directly, not through
index->set_lock() so mbox lock won't be affected). */
return FALSE;
}
if ((flags & MAIL_INDEX_OPEN_FLAG_FAST) == 0) {
/* remove deleted blocks from index file */
if (!mail_index_compress(index))
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 updates which may move data
and create unused space */
if (!mail_index_compress_data(index))
return FALSE;
}
}
return FALSE;
return TRUE;
}
struct mail_index_header *hdr)
{
if (ret < 0) {
return -1;
}
/* missing data */
return 0;
}
return 1;
}
{
}
struct mail_index_header *hdr)
{
INDEX_MIN_RECORDS_COUNT * sizeof(struct mail_index_record);
return FALSE;
}
return FALSE;
}
return FALSE;
}
return TRUE;
}
struct mail_index_header *hdr)
{
/* mark the index requiring rebuild - rebuild() removes this flag
when it succeeds */
/* set the fields we always want to cache,
but not if we're building into memory */
}
}
static void mail_index_cleanup_temp_files(const char *dir)
{
}
{
}
}
enum mail_index_open_flags flags)
{
if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0)
return FALSE;
}
return FALSE;
}
return TRUE;
}
enum mail_index_open_flags flags)
{
struct mail_index_header hdr;
int ret;
if ((flags & _MAIL_INDEX_OPEN_FLAG_CREATING) == 0)
else
/* if index is being created, we'll wait here until it's finished */
return FALSE;
#ifdef DEBUG
}
#endif
return FALSE;
if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0)
return FALSE;
/* so, we're creating the index */
/* have to get exclusive lock first */
return FALSE;
}
return FALSE;
}
if (!mail_index_mmap_update(index))
return FALSE;
/* we don't want to keep the shared lock while opening
indexes. opening should work unlocked and some
things want exclusive lock */
return FALSE;
}
(flags & _MAIL_INDEX_OPEN_FLAG_CREATING) != 0)
return FALSE;
/* needs a rebuild */
return FALSE;
}
return FALSE;
return TRUE;
}
{
const char *path;
if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) != 0)
else
}
}
return TRUE;
}