Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8629:1efdf705203c HEAD
Maildir keywords handling code cleanup.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 15 Jan 2009 15:05:58 -0500 |
parents | e85c7cb22ad7 |
children | ee7c5ec212bb |
files | src/lib-storage/index/maildir/maildir-keywords.c |
diffstat | 1 files changed, 16 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-keywords.c Wed Jan 14 15:14:11 2009 -0500 +++ b/src/lib-storage/index/maildir/maildir-keywords.c Thu Jan 15 15:05:58 2009 -0500 @@ -190,24 +190,27 @@ } static int -maildir_keywords_lookup(struct maildir_keywords *mk, const char *name) +maildir_keywords_lookup(struct maildir_keywords *mk, const char *name, + unsigned int *chridx_r) { void *p; p = hash_table_lookup(mk->hash, name); if (p == NULL) { if (mk->synced) - return -1; + return 0; if (maildir_keywords_sync(mk) < 0) return -1; + i_assert(mk->synced); p = hash_table_lookup(mk->hash, name); if (p == NULL) - return -1; + return 0; } - return POINTER_CAST_TO(p, int)-1; + *chridx_r = POINTER_CAST_TO(p, int)-1; + return 1; } static void @@ -229,19 +232,15 @@ } static int -maildir_keywords_lookup_or_create(struct maildir_keywords *mk, const char *name) +maildir_keywords_lookup_or_create(struct maildir_keywords *mk, const char *name, + unsigned int *chridx_r) { const char *const *keywords; unsigned int i, count; - int idx; + int ret; - idx = maildir_keywords_lookup(mk, name); - if (idx >= 0) - return idx; - if (!mk->synced) { - /* we couldn't open the dovecot-keywords file. */ - return -1; - } + if ((ret = maildir_keywords_lookup(mk, name, chridx_r)) != 0) + return ret; /* see if we are full */ keywords = array_get(&mk->list, &count); @@ -273,6 +272,7 @@ if (maildir_keywords_sync(mk) < 0) return NULL; + i_assert(mk->synced); keywords = array_get(&mk->list, &count); } @@ -435,7 +435,7 @@ if (name == NULL) { /* name is lost. just generate one ourself. */ name = t_strdup_printf("unknown-%u", chridx); - while (maildir_keywords_lookup(ctx->mk, name) >= 0) { + while (maildir_keywords_lookup(ctx->mk, name, &idx) > 0) { /* don't create a duplicate name. keep changing the name until it doesn't exist */ name = t_strconcat(name, "?", NULL); @@ -453,15 +453,14 @@ { const char *const *name_p; char *chr_p; - int chridx; + unsigned int chridx; chr_p = array_idx_modifiable(&ctx->idx_to_chr, idx); if (*chr_p != '\0') return *chr_p; name_p = array_idx(ctx->keywords, idx); - chridx = maildir_keywords_lookup_or_create(ctx->mk, *name_p); - if (chridx < 0) + if (maildir_keywords_lookup_or_create(ctx->mk, *name_p, &chridx) <= 0) return '\0'; *chr_p = chridx + MAILDIR_KEYWORD_FIRST;