[dovecot-cvs] dovecot/src/lib-index mail-hash.c, 1.21, 1.22 mail-hash.h, 1.9, 1.10
tss-movial at dovecot.org
tss-movial at dovecot.org
Mon Jul 31 02:07:48 EEST 2006
Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv25523/lib-index
Modified Files:
mail-hash.c mail-hash.h
Log Message:
Delay creating thread index file until THREAD command is used for the first time.
Index: mail-hash.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-hash.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- mail-hash.c 11 Jul 2006 16:04:21 -0000 1.21
+++ mail-hash.c 30 Jul 2006 23:07:46 -0000 1.22
@@ -505,10 +505,11 @@
}
struct mail_hash *
-mail_hash_open_or_create(struct mail_index *index, const char *suffix,
- unsigned int record_size, hash_callback_t *hash_cb,
- hash_ctx_cmp_callback_t *key_compare_cb,
- void *context, bool in_memory)
+mail_hash_open(struct mail_index *index, const char *suffix,
+ enum mail_hash_open_flags flags,
+ unsigned int record_size, hash_callback_t *hash_cb,
+ hash_ctx_cmp_callback_t *key_compare_cb,
+ void *context)
{
struct mail_hash *hash;
int ret;
@@ -517,7 +518,8 @@
hash = i_new(struct mail_hash, 1);
hash->index = index;
- hash->filepath = in_memory ? "(in-memory hash" :
+ hash->filepath = (flags & MAIL_HASH_OPEN_FLAG_IN_MEMORY) != 0 ?
+ i_strdup("(in-memory hash)") :
i_strconcat(index->filepath, suffix, NULL);
hash->record_size = record_size;
hash->fd = -1;
@@ -526,8 +528,15 @@
hash->key_compare_cb = key_compare_cb;
hash->cb_context = context;
- ret = MAIL_INDEX_IS_IN_MEMORY(hash->index) || in_memory ? -1 :
+ ret = MAIL_INDEX_IS_IN_MEMORY(hash->index) ||
+ (flags & MAIL_HASH_OPEN_FLAG_IN_MEMORY) != 0 ? -1 :
mail_hash_file_open(hash);
+
+ if (ret <= 0 && (flags & MAIL_HASH_OPEN_FLAG_CREATE) == 0) {
+ /* we don't want to create the hash */
+ mail_hash_free(&hash);
+ return NULL;
+ }
if (ret == 0) {
/* not found or broken, recreate it */
ret = mail_hash_reset(hash);
@@ -547,6 +556,7 @@
*_hash = NULL;
mail_hash_file_close(hash);
+ i_free(hash->filepath);
i_free(hash);
}
@@ -857,11 +867,11 @@
"Tried to remove non-existing key");
return -1;
}
- }
- if (mail_hash_mark_update(hash, idx_p, sizeof(*idx_p)) < 0)
- return -1;
- *idx_p = rec->next_idx;
+ if (mail_hash_mark_update(hash, idx_p, sizeof(*idx_p)) < 0)
+ return -1;
+ *idx_p = rec->next_idx;
+ }
if (rec->uid != 0) {
if (hash->hdr->message_count == 0) {
Index: mail-hash.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-hash.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mail-hash.h 11 Jul 2006 16:04:21 -0000 1.9
+++ mail-hash.h 30 Jul 2006 23:07:46 -0000 1.10
@@ -52,6 +52,11 @@
/* user_data[] */
};
+enum mail_hash_open_flags {
+ MAIL_HASH_OPEN_FLAG_CREATE = 0x01,
+ MAIL_HASH_OPEN_FLAG_IN_MEMORY = 0x02
+};
+
/* Returns hash code. */
typedef unsigned int hash_ctx_callback_t(const void *p, void *context);
/* Returns 0 if the pointers are equal. */
@@ -59,10 +64,11 @@
void *context);
struct mail_hash *
-mail_hash_open_or_create(struct mail_index *index, const char *suffix,
- unsigned int record_size, hash_callback_t *hash_cb,
- hash_ctx_cmp_callback_t *key_compare_cb,
- void *context, bool in_memory);
+mail_hash_open(struct mail_index *index, const char *suffix,
+ enum mail_hash_open_flags flags,
+ unsigned int record_size, hash_callback_t *hash_cb,
+ hash_ctx_cmp_callback_t *key_compare_cb,
+ void *context);
void mail_hash_free(struct mail_hash **hash);
int mail_hash_reset(struct mail_hash *hash);
More information about the dovecot-cvs
mailing list