summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2002-09-24 01:16:12 +0000
committerMichael Zucci <zucchi@src.gnome.org>2002-09-24 01:16:12 +0000
commit5de5dd868ae3236199d2f9629b97927b45d55457 (patch)
tree4be7cc61fdf4ed300d4bc3aba1861d2e13330be1
parent80b92416ecc711ff55d1f099c5b62b502f2d6407 (diff)
downloadevolution-data-server-5de5dd868ae3236199d2f9629b97927b45d55457.tar.gz
If we have no data written to a key, dont add it, or its partition header.
2002-09-24 Not Zed <NotZed@Ximian.com> * camel-text-index.c (text_index_compress_nosync): If we have no data written to a key, dont add it, or its partition header. 2002-09-23 Not Zed <NotZed@Ximian.com> * camel-block-file.c (sync_nolock): Mark root block dirty if we're going to sync it. (camel_key_file_finalise): de-count the active list if we close it. * camel-text-index.c (text_index_delete): Implement. (text_index_compress_nosync): Use index_delete when we're finished with the old one, so it is properly deactivated. * camel-index.c (camel_index_delete): Remove api call. Mark index deleted in new state variable. (camel_index_*): Wrap all calls in check for deleted state.
-rw-r--r--camel/ChangeLog20
-rw-r--r--camel/camel-block-file.c5
-rw-r--r--camel/camel-index.c75
-rw-r--r--camel/camel-index.h8
-rw-r--r--camel/camel-text-index.c38
-rw-r--r--camel/camel-text-index.h1
6 files changed, 123 insertions, 24 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 320eebc4c..ac6d0eb5e 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,23 @@
+2002-09-24 Not Zed <NotZed@Ximian.com>
+
+ * camel-text-index.c (text_index_compress_nosync): If we have no
+ data written to a key, dont add it, or its partition header.
+
+2002-09-23 Not Zed <NotZed@Ximian.com>
+
+ * camel-block-file.c (sync_nolock): Mark root block dirty if we're
+ going to sync it.
+ (camel_key_file_finalise): de-count the active list if we close
+ it.
+
+ * camel-text-index.c (text_index_delete): Implement.
+ (text_index_compress_nosync): Use index_delete when we're finished
+ with the old one, so it is properly deactivated.
+
+ * camel-index.c (camel_index_delete): Remove api call. Mark index
+ deleted in new state variable.
+ (camel_index_*): Wrap all calls in check for deleted state.
+
2002-09-23 Jeffrey Stedfast <fejj@ximian.com>
* camel-folder.c (transfer_message_to): If the original message is
diff --git a/camel/camel-block-file.c b/camel/camel-block-file.c
index e61320b2e..3ba97ba55 100644
--- a/camel/camel-block-file.c
+++ b/camel/camel-block-file.c
@@ -713,6 +713,7 @@ sync_nolock(CamelBlockFile *bs)
d(printf("turning on sync flag\n"));
bs->root->flags |= CAMEL_BLOCK_FILE_SYNC;
+ bs->root_block->flags |= CAMEL_BLOCK_DIRTY;
return sync_block_nolock(bs, bs->root_block);
}
@@ -834,8 +835,10 @@ camel_key_file_finalise(CamelKeyFile *bs)
e_dlist_remove((EDListNode *)p);
UNLOCK(key_file_lock);
- if (bs->fp)
+ if (bs-> fp) {
+ key_file_count--;
fclose(bs->fp);
+ }
g_free(bs->path);
#ifdef ENABLE_THREADS
diff --git a/camel/camel-index.c b/camel/camel-index.c
index eb476b41f..ea7a63fe0 100644
--- a/camel/camel-index.c
+++ b/camel/camel-index.c
@@ -116,7 +116,12 @@ camel_index_construct(CamelIndex *idx, const char *path, int flags)
int
camel_index_rename(CamelIndex *idx, const char *path)
{
- return CI_CLASS(idx)->rename(idx, path);
+ if ((idx->state & CAMEL_INDEX_DELETED) == 0)
+ return CI_CLASS(idx)->rename(idx, path);
+ else {
+ errno = ENOENT;
+ return -1;
+ }
}
void
@@ -129,43 +134,84 @@ camel_index_set_normalise(CamelIndex *idx, CamelIndexNorm func, void *data)
int
camel_index_sync(CamelIndex *idx)
{
- return CI_CLASS(idx)->sync(idx);
+ if ((idx->state & CAMEL_INDEX_DELETED) == 0)
+ return CI_CLASS(idx)->sync(idx);
+ else {
+ errno = ENOENT;
+ return -1;
+ }
}
int
camel_index_compress(CamelIndex *idx)
{
- return CI_CLASS(idx)->compress(idx);
+ if ((idx->state & CAMEL_INDEX_DELETED) == 0)
+ return CI_CLASS(idx)->compress(idx);
+ else {
+ errno = ENOENT;
+ return -1;
+ }
+}
+
+int
+camel_index_delete(CamelIndex *idx)
+{
+ int ret;
+
+ if ((idx->state & CAMEL_INDEX_DELETED) == 0) {
+ ret = CI_CLASS(idx)->delete(idx);
+ idx->state |= CAMEL_INDEX_DELETED;
+ } else {
+ errno = ENOENT;
+ ret = -1;
+ }
+
+ return ret;
}
int
camel_index_has_name(CamelIndex *idx, const char *name)
{
- return CI_CLASS(idx)->has_name(idx, name);
+ if ((idx->state & CAMEL_INDEX_DELETED) == 0)
+ return CI_CLASS(idx)->has_name(idx, name);
+ else
+ return FALSE;
}
CamelIndexName *
camel_index_add_name(CamelIndex *idx, const char *name)
{
- return CI_CLASS(idx)->add_name(idx, name);
+ if ((idx->state & CAMEL_INDEX_DELETED) == 0)
+ return CI_CLASS(idx)->add_name(idx, name);
+ else
+ return NULL;
}
int
camel_index_write_name(CamelIndex *idx, CamelIndexName *idn)
{
- return CI_CLASS(idx)->write_name(idx, idn);
+ if ((idx->state & CAMEL_INDEX_DELETED) == 0)
+ return CI_CLASS(idx)->write_name(idx, idn);
+ else {
+ errno = ENOENT;
+ return -1;
+ }
}
CamelIndexCursor *
camel_index_find_name(CamelIndex *idx, const char *name)
{
- return CI_CLASS(idx)->find_name(idx, name);
+ if ((idx->state & CAMEL_INDEX_DELETED) == 0)
+ return CI_CLASS(idx)->find_name(idx, name);
+ else
+ return NULL;
}
void
camel_index_delete_name(CamelIndex *idx, const char *name)
{
- return CI_CLASS(idx)->delete_name(idx, name);
+ if ((idx->state & CAMEL_INDEX_DELETED) == 0)
+ CI_CLASS(idx)->delete_name(idx, name);
}
CamelIndexCursor *
@@ -174,6 +220,9 @@ camel_index_find(CamelIndex *idx, const char *word)
char *b = (char *)word;
CamelIndexCursor *ret;
+ if ((idx->state & CAMEL_INDEX_DELETED) != 0)
+ return NULL;
+
if (idx->normalise)
b = idx->normalise(idx, word, idx->normalise_data);
@@ -188,13 +237,19 @@ camel_index_find(CamelIndex *idx, const char *word)
CamelIndexCursor *
camel_index_words(CamelIndex *idx)
{
- return CI_CLASS(idx)->words(idx);
+ if ((idx->state & CAMEL_INDEX_DELETED) == 0)
+ return CI_CLASS(idx)->words(idx);
+ else
+ return NULL;
}
CamelIndexCursor *
camel_index_names(CamelIndex *idx)
{
- return CI_CLASS(idx)->names(idx);
+ if ((idx->state & CAMEL_INDEX_DELETED) == 0)
+ return CI_CLASS(idx)->names(idx);
+ else
+ return NULL;
}
/* ********************************************************************** */
diff --git a/camel/camel-index.h b/camel/camel-index.h
index 81b84c3d3..0382dc1d0 100644
--- a/camel/camel-index.h
+++ b/camel/camel-index.h
@@ -110,7 +110,8 @@ struct _CamelIndex {
char *path;
guint32 version;
- guint32 flags;
+ guint32 flags; /* open flags */
+ guint32 state;
CamelIndexNorm normalise;
void *normalise_data;
@@ -121,6 +122,7 @@ struct _CamelIndexClass {
int (*sync)(CamelIndex *idx);
int (*compress)(CamelIndex *idx);
+ int (*delete)(CamelIndex *idx);
int (*rename)(CamelIndex *idx, const char *path);
@@ -135,6 +137,9 @@ struct _CamelIndexClass {
CamelIndexCursor * (*names)(CamelIndex *idx);
};
+/* flags, stored in 'state', set with set_state */
+#define CAMEL_INDEX_DELETED (1<<0)
+
CamelType camel_index_get_type (void);
CamelIndex *camel_index_new(const char *path, int flags);
@@ -145,6 +150,7 @@ void camel_index_set_normalise(CamelIndex *idx, CamelIndexNorm fun
int camel_index_sync(CamelIndex *idx);
int camel_index_compress(CamelIndex *idx);
+int camel_index_delete(CamelIndex *idx);
int camel_index_has_name(CamelIndex *idx, const char *name);
CamelIndexName *camel_index_add_name(CamelIndex *idx, const char *name);
diff --git a/camel/camel-text-index.c b/camel/camel-text-index.c
index 3c490804f..e34051113 100644
--- a/camel/camel-text-index.c
+++ b/camel/camel-text-index.c
@@ -263,6 +263,8 @@ text_index_sync(CamelIndex *idx)
struct _CamelTextIndexRoot *rb;
int ret = 0, wfrag, nfrag, work = FALSE;
+ d(printf("sync: blocks = %p\n", p->blocks));
+
if (p->blocks == NULL)
return 0;
@@ -304,11 +306,12 @@ text_index_sync(CamelIndex *idx)
ret = -1;
/* only do the frag/compress check if we did some new writes on this index */
- if (ret == 0 && work) {
- wfrag = rb->words ? (((rb->keys - rb->words) * 100)/ rb->words) : 0;
- nfrag = rb->names ? ((rb->deleted * 100) / rb->names) : 0;
- d(printf("wfrag = %d, nfrag = %d\n", wfrag, nfrag));
- d(printf(" words = %d, keys = %d\n", rb->words, rb->keys));
+ wfrag = rb->words ? (((rb->keys - rb->words) * 100)/ rb->words) : 0;
+ nfrag = rb->names ? ((rb->deleted * 100) / rb->names) : 0;
+ d(printf("wfrag = %d, nfrag = %d, work = %s, ret = %d\n", wfrag, nfrag, work?"true":"false", ret));
+ d(printf(" words = %d, keys = %d\n", rb->words, rb->keys));
+
+ if (ret == 0) {
if (wfrag > 30 || nfrag > 20)
ret = text_index_compress_nosync(idx);
}
@@ -466,11 +469,13 @@ text_index_compress_nosync(CamelIndex *idx)
if (camel_key_file_write(newp->links, &newdata, newcount, newrecords) == -1)
goto fail;
}
-
- newkeyid = camel_key_table_add(newp->word_index, name, newdata, flags);
- if (newkeyid == 0)
- goto fail;
- camel_partition_table_add(newp->word_hash, name, newkeyid);
+
+ if (newdata != 0) {
+ newkeyid = camel_key_table_add(newp->word_index, name, newdata, flags);
+ if (newkeyid == 0)
+ goto fail;
+ camel_partition_table_add(newp->word_hash, name, newkeyid);
+ }
g_free(name);
name = NULL;
}
@@ -505,13 +510,13 @@ text_index_compress_nosync(CamelIndex *idx)
fail:
CAMEL_TEXT_INDEX_UNLOCK(idx, lock);
+ camel_index_delete((CamelIndex *)newidx);
+
camel_object_unref((CamelObject *)newidx);
g_free(name);
g_hash_table_destroy(remap);
/* clean up temp files always */
- camel_text_index_remove(newpath);
-
sprintf(savepath, "%s~.index", oldpath);
unlink(savepath);
sprintf(newpath, "%s.data", savepath);
@@ -521,6 +526,12 @@ fail:
}
static int
+text_index_delete(CamelIndex *idx)
+{
+ return camel_text_index_remove(idx->path);
+}
+
+static int
text_index_rename(CamelIndex *idx, const char *path)
{
struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
@@ -649,6 +660,8 @@ text_index_delete_name(CamelIndex *idx, const char *name)
camel_key_t keyid;
struct _CamelTextIndexRoot *rb = (struct _CamelTextIndexRoot *)p->blocks->root;
+ d(printf("Delete name: %s\n", name));
+
/* probably doesn't really need locking, but oh well */
CAMEL_TEXT_INDEX_LOCK(idx, lock);
@@ -714,6 +727,7 @@ camel_text_index_class_init(CamelTextIndexClass *klass)
iklass->sync = text_index_sync;
iklass->compress = text_index_compress;
+ iklass->delete = text_index_delete;
iklass->rename = text_index_rename;
diff --git a/camel/camel-text-index.h b/camel/camel-text-index.h
index 09b8fc0db..fd9e6aa11 100644
--- a/camel/camel-text-index.h
+++ b/camel/camel-text-index.h
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) 2001 Ximian Inc.
*