Mercurial > dovecot > original-hg > dovecot-1.2
changeset 9017:0aa17f3e4a6d HEAD
Maildir: Handle uidlist errors better.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 04 May 2009 16:42:43 -0400 |
parents | 6770f46971af |
children | 0bb192fe0abd |
files | src/lib-storage/index/maildir/maildir-copy.c src/lib-storage/index/maildir/maildir-mail.c src/lib-storage/index/maildir/maildir-sync.c src/lib-storage/index/maildir/maildir-uidlist.c src/lib-storage/index/maildir/maildir-uidlist.h src/lib-storage/index/maildir/maildir-util.c |
diffstat | 6 files changed, 73 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-copy.c Mon May 04 14:28:31 2009 -0400 +++ b/src/lib-storage/index/maildir/maildir-copy.c Mon May 04 16:42:43 2009 -0400 @@ -167,9 +167,9 @@ uidlist. if it doesn't, we can use it. otherwise generate a new filename. FIXME: There's a race condition here if another process is just doing the same copy. */ - src_fname = maildir_uidlist_lookup(src_mbox->uidlist, - mail->uid, &src_flags); - if (src_fname != NULL && + if (maildir_uidlist_lookup(src_mbox->uidlist, + mail->uid, &src_flags, + &src_fname) > 0 && maildir_uidlist_refresh(dest_mbox->uidlist) >= 0 && maildir_uidlist_get_full_filename(dest_mbox->uidlist, src_fname) == NULL)
--- a/src/lib-storage/index/maildir/maildir-mail.c Mon May 04 14:28:31 2009 -0400 +++ b/src/lib-storage/index/maildir/maildir-mail.c Mon May 04 16:42:43 2009 -0400 @@ -147,7 +147,7 @@ return data->save_date; } -static bool +static int maildir_mail_get_fname(struct maildir_mailbox *mbox, struct mail *mail, const char **fname_r) { @@ -155,10 +155,11 @@ struct mail_index_view *view; uint32_t seq; bool exists; + int ret; - *fname_r = maildir_uidlist_lookup(mbox->uidlist, mail->uid, &flags); - if (*fname_r != NULL) - return TRUE; + ret = maildir_uidlist_lookup(mbox->uidlist, mail->uid, &flags, fname_r); + if (ret != 0) + return ret; /* file exists in index file, but not in dovecot-uidlist anymore. */ mail_set_expunged(mail); @@ -177,7 +178,7 @@ the same as in index. fix this by forcing a resync. */ (void)maildir_storage_sync_force(mbox, mail->uid); } - return FALSE; + return 0; } static int maildir_get_pop3_state(struct index_mail *mail) @@ -252,7 +253,7 @@ char *p; if (_mail->uid != 0) { - if (!maildir_mail_get_fname(mbox, _mail, &fname)) + if (maildir_mail_get_fname(mbox, _mail, &fname) <= 0) return -1; } else { path = maildir_save_file_get_path(_mail->transaction, @@ -428,7 +429,7 @@ case MAIL_FETCH_UIDL_FILE_NAME: case MAIL_FETCH_GUID: if (_mail->uid != 0) { - if (!maildir_mail_get_fname(mbox, _mail, &fname)) + if (maildir_mail_get_fname(mbox, _mail, &fname) <= 0) return -1; } else { path = maildir_save_file_get_path(_mail->transaction, @@ -488,12 +489,15 @@ enum maildir_uidlist_rec_flag flags; const char *fname; uoff_t size; + int ret; if (field == MAIL_FETCH_VIRTUAL_SIZE) { /* make sure it gets removed from uidlist. if it's in file name, we can't really do more than log it. */ - fname = maildir_uidlist_lookup(mbox->uidlist, - _mail->uid, &flags); + ret = maildir_uidlist_lookup(mbox->uidlist, _mail->uid, + &flags, &fname); + if (ret <= 0) + return; if (maildir_filename_get_size(fname, MAILDIR_EXTRA_VIRTUAL_SIZE, &size)) { const char *subdir =
--- a/src/lib-storage/index/maildir/maildir-sync.c Mon May 04 14:28:31 2009 -0400 +++ b/src/lib-storage/index/maildir/maildir-sync.c Mon May 04 16:42:43 2009 -0400 @@ -690,6 +690,7 @@ enum maildir_uidlist_sync_flags sync_flags; enum maildir_uidlist_rec_flag flags; bool new_changed, cur_changed, lock_failure; + const char *fname; int ret; *lost_files_r = FALSE; @@ -852,8 +853,11 @@ } if (find_uid != NULL && *find_uid != 0) { - if (maildir_uidlist_lookup_nosync(ctx->mbox->uidlist, *find_uid, - &flags) == NULL) { + ret = maildir_uidlist_lookup_nosync(ctx->mbox->uidlist, + *find_uid, &flags, &fname); + if (ret < 0) + return -1; + if (ret == 0) { /* UID is expunged */ *find_uid = 0; } else if ((flags & MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) == 0) {
--- a/src/lib-storage/index/maildir/maildir-uidlist.c Mon May 04 14:28:31 2009 -0400 +++ b/src/lib-storage/index/maildir/maildir-uidlist.c Mon May 04 16:42:43 2009 -0400 @@ -859,9 +859,10 @@ } } -static struct maildir_uidlist_rec * +static int maildir_uidlist_lookup_rec(struct maildir_uidlist *uidlist, uint32_t uid, - unsigned int *idx_r) + unsigned int *idx_r, + struct maildir_uidlist_rec **rec_r) { struct maildir_uidlist_rec *const *recs; unsigned int idx, left_idx, right_idx; @@ -869,7 +870,7 @@ if (!uidlist->initial_read) { /* first time we need to read uidlist */ if (maildir_uidlist_refresh(uidlist) < 0) - return NULL; + return -1; } idx = left_idx = 0; @@ -883,66 +884,72 @@ right_idx = idx; else { *idx_r = idx; - return recs[idx]; + *rec_r = recs[idx]; + return 1; } } if (idx > 0) idx--; *idx_r = idx; - return NULL; + return 0; } -const char * -maildir_uidlist_lookup(struct maildir_uidlist *uidlist, uint32_t uid, - enum maildir_uidlist_rec_flag *flags_r) +int maildir_uidlist_lookup(struct maildir_uidlist *uidlist, uint32_t uid, + enum maildir_uidlist_rec_flag *flags_r, + const char **fname_r) { - const char *fname; + int ret; - fname = maildir_uidlist_lookup_nosync(uidlist, uid, flags_r); - if (fname == NULL) { + ret = maildir_uidlist_lookup_nosync(uidlist, uid, flags_r, fname_r); + if (ret <= 0) { + if (ret < 0) + return -1; if (uidlist->fd != -1 || uidlist->mbox == NULL) { /* refresh uidlist and check again in case it was added after the last mailbox sync */ if (maildir_uidlist_refresh(uidlist) < 0) - return NULL; + return -1; } else { /* the uidlist doesn't exist. */ if (maildir_storage_sync_force(uidlist->mbox, uid) < 0) - return NULL; + return -1; } /* try again */ - fname = maildir_uidlist_lookup_nosync(uidlist, uid, flags_r); + ret = maildir_uidlist_lookup_nosync(uidlist, uid, + flags_r, fname_r); } - return fname; + return ret; } -const char * -maildir_uidlist_lookup_nosync(struct maildir_uidlist *uidlist, uint32_t uid, - enum maildir_uidlist_rec_flag *flags_r) +int maildir_uidlist_lookup_nosync(struct maildir_uidlist *uidlist, uint32_t uid, + enum maildir_uidlist_rec_flag *flags_r, + const char **fname_r) { - const struct maildir_uidlist_rec *rec; + struct maildir_uidlist_rec *rec; unsigned int idx; + int ret; - rec = maildir_uidlist_lookup_rec(uidlist, uid, &idx); - if (rec == NULL) - return NULL; + if ((ret = maildir_uidlist_lookup_rec(uidlist, uid, &idx, &rec)) <= 0) + return ret; *flags_r = rec->flags; - return rec->filename; + *fname_r = rec->filename; + return 1; } const char * maildir_uidlist_lookup_ext(struct maildir_uidlist *uidlist, uint32_t uid, enum maildir_uidlist_rec_ext_key key) { - const struct maildir_uidlist_rec *rec; + struct maildir_uidlist_rec *rec; unsigned int idx; const unsigned char *p; + int ret; - rec = maildir_uidlist_lookup_rec(uidlist, uid, &idx); - if (rec == NULL || rec->extensions == NULL) + ret = maildir_uidlist_lookup_rec(uidlist, uid, &idx, &rec); + if (ret <= 0 || rec->extensions == NULL) return NULL; p = rec->extensions; @@ -991,14 +998,17 @@ const unsigned char *p; buffer_t *buf; unsigned int len; + int ret; - rec = maildir_uidlist_lookup_rec(uidlist, uid, &idx); - if (rec == NULL) { + ret = maildir_uidlist_lookup_rec(uidlist, uid, &idx, &rec); + if (ret <= 0) { + if (ret < 0) + return; + /* maybe it's a new message */ if (maildir_uidlist_refresh(uidlist) < 0) return; - rec = maildir_uidlist_lookup_rec(uidlist, uid, &idx); - if (rec == NULL) { + if (maildir_uidlist_lookup_rec(uidlist, uid, &idx, &rec) <= 0) { /* message is already expunged, ignore */ return; }
--- a/src/lib-storage/index/maildir/maildir-uidlist.h Mon May 04 14:28:31 2009 -0400 +++ b/src/lib-storage/index/maildir/maildir-uidlist.h Mon May 04 16:42:43 2009 -0400 @@ -64,13 +64,14 @@ fill in the uidvalidity/nextuid from index file instead. */ int maildir_uidlist_refresh_fast_init(struct maildir_uidlist *uidlist); -/* Returns uidlist record for given filename, or NULL if not found. */ -const char * -maildir_uidlist_lookup(struct maildir_uidlist *uidlist, uint32_t uid, - enum maildir_uidlist_rec_flag *flags_r); -const char * -maildir_uidlist_lookup_nosync(struct maildir_uidlist *uidlist, uint32_t uid, - enum maildir_uidlist_rec_flag *flags_r); +/* Look up uidlist record for given filename. Returns 1 if found, + 0 if not found, -1 if error */ +int maildir_uidlist_lookup(struct maildir_uidlist *uidlist, uint32_t uid, + enum maildir_uidlist_rec_flag *flags_r, + const char **fname_r); +int maildir_uidlist_lookup_nosync(struct maildir_uidlist *uidlist, uint32_t uid, + enum maildir_uidlist_rec_flag *flags_r, + const char **fname_r); /* Returns extension's value or NULL if it doesn't exist. */ const char * maildir_uidlist_lookup_ext(struct maildir_uidlist *uidlist, uint32_t uid,
--- a/src/lib-storage/index/maildir/maildir-util.c Mon May 04 14:28:31 2009 -0400 +++ b/src/lib-storage/index/maildir/maildir-util.c Mon May 04 16:42:43 2009 -0400 @@ -59,9 +59,9 @@ bool have_flags; int ret; - fname = maildir_uidlist_lookup(mbox->uidlist, uid, &flags); - if (fname == NULL) - return -2; /* expunged */ + ret = maildir_uidlist_lookup(mbox->uidlist, uid, &flags, &fname); + if (ret <= 0) + return ret == 0 ? -2 : -1; if ((flags & MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { /* let's see if we can guess the filename based on index */