Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6768:f8baedac2417 HEAD
dbox fixes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 10 Nov 2007 23:40:36 +0200 |
parents | 51793c88b1c7 |
children | 3ac33cc68f24 |
files | src/lib-storage/index/dbox/dbox-file.c src/lib-storage/index/dbox/dbox-file.h src/lib-storage/index/dbox/dbox-mail.c src/lib-storage/index/dbox/dbox-sync-file.c src/lib-storage/index/dbox/dbox-sync-rebuild.c src/lib-storage/index/maildir/maildir-keywords.c |
diffstat | 6 files changed, 35 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-file.c Sat Nov 10 23:37:10 2007 +0200 +++ b/src/lib-storage/index/dbox/dbox-file.c Sat Nov 10 23:40:36 2007 +0200 @@ -570,17 +570,22 @@ if (offset == 0) offset = file->file_header_size; - i_stream_seek(file->input, offset); - ret = dbox_file_read_mail_header(file, uid_r, physical_size_r); - if (ret <= 0) - return ret; - - i_stream_skip(file->input, file->msg_header_size); + if (offset != file->cur_offset) { + file->cur_offset = offset; + i_stream_seek(file->input, offset); + ret = dbox_file_read_mail_header(file, &file->cur_uid, + &file->cur_physical_size); + if (ret <= 0) + return ret; + } if (stream_r != NULL) { + i_stream_seek(file->input, offset + file->msg_header_size); *stream_r = i_stream_create_limit(file->input, file->input->v_offset, - *physical_size_r); + file->cur_physical_size); } + *uid_r = file->cur_uid; + *physical_size_r = file->cur_physical_size; return 1; } @@ -737,8 +742,9 @@ file->append_count++; } -uoff_t dbox_file_get_metadata_offset(struct dbox_file *file, uoff_t offset, - uoff_t physical_size) +static uoff_t +dbox_file_get_metadata_offset(struct dbox_file *file, uoff_t offset, + uoff_t physical_size) { if (offset == 0) { if (file->maildir_file) @@ -844,21 +850,16 @@ { uoff_t physical_size, metadata_offset; uint32_t uid; - bool expunged1, expunged2; int ret; ret = dbox_file_get_mail_stream(file, offset, &uid, &physical_size, - NULL, &expunged1); - if (ret <= 0) + NULL, expunged_r); + if (ret <= 0 || *expunged_r) return ret; metadata_offset = dbox_file_get_metadata_offset(file, offset, physical_size); - ret = dbox_file_metadata_seek(file, metadata_offset, &expunged2); - if (ret <= 0) - return ret; - *expunged_r = expunged1 || expunged2; - return 1; + return dbox_file_metadata_seek(file, metadata_offset, expunged_r); } const char *dbox_file_metadata_get(struct dbox_file *file, @@ -1128,7 +1129,9 @@ mail_index_lookup_ext(view, seq, mbox->dbox_ext_id, &data, &expunged); if (expunged) return FALSE; - if (data == NULL) { + dbox_rec = data; + + if (dbox_rec == NULL || dbox_rec->file_id == 0) { mail_index_lookup_uid(view, seq, &uid); if ((uid & DBOX_FILE_ID_FLAG_UID) != 0) { /* something's broken, we can't handle this high UIDs */ @@ -1137,7 +1140,6 @@ *file_id_r = DBOX_FILE_ID_FLAG_UID | uid; *offset_r = 0; } else { - dbox_rec = data; *file_id_r = dbox_rec->file_id; *offset_r = dbox_rec->offset; }
--- a/src/lib-storage/index/dbox/dbox-file.h Sat Nov 10 23:37:10 2007 +0200 +++ b/src/lib-storage/index/dbox/dbox-file.h Sat Nov 10 23:40:36 2007 +0200 @@ -108,6 +108,10 @@ time_t create_time; uoff_t output_stream_offset; + uoff_t cur_offset; + uint32_t cur_uid; + uoff_t cur_physical_size; + char *fname; char *current_path; @@ -181,9 +185,6 @@ /* Finish appending the current mail. */ void dbox_file_finish_append(struct dbox_file *file); -/* Calculate offset to message's metadata. */ -uoff_t dbox_file_get_metadata_offset(struct dbox_file *file, uoff_t offset, - uoff_t physical_size); /* Seek to given metadata block. Returns 1 if ok, 0 if file/offset is corrupted, -1 if I/O error. If message has already been expunged, expunged_r=TRUE and 1 is returned. */
--- a/src/lib-storage/index/dbox/dbox-mail.c Sat Nov 10 23:37:10 2007 +0200 +++ b/src/lib-storage/index/dbox/dbox-mail.c Sat Nov 10 23:40:36 2007 +0200 @@ -64,20 +64,14 @@ static int dbox_mail_metadata_seek(struct dbox_mail *mail, struct dbox_file **file_r) { - struct mail *_mail = &mail->imail.mail.mail; - uoff_t offset, metadata_offset, physical_size; + uoff_t offset; bool expunged; int ret; if (dbox_mail_lookup(mail, &offset, file_r) < 0) return -1; - if (mail_get_physical_size(_mail, &physical_size) < 0) - return -1; - - metadata_offset = - dbox_file_get_metadata_offset(*file_r, offset, physical_size); - ret = dbox_file_metadata_seek(*file_r, metadata_offset, &expunged); + ret = dbox_file_metadata_seek_mail_offset(*file_r, offset, &expunged); if (ret <= 0) { if (ret < 0) return -1;
--- a/src/lib-storage/index/dbox/dbox-sync-file.c Sat Nov 10 23:37:10 2007 +0200 +++ b/src/lib-storage/index/dbox/dbox-sync-file.c Sat Nov 10 23:40:36 2007 +0200 @@ -94,7 +94,7 @@ struct istream *input; struct ostream *output; uint32_t file_id, seq, uid; - uoff_t first_offset, offset, physical_size, metadata_offset; + uoff_t first_offset, offset, physical_size; const char *out_path; unsigned int i, count; bool expunged; @@ -151,9 +151,8 @@ break; /* write metadata */ - metadata_offset = dbox_file_get_metadata_offset(file, offset, - physical_size); - (void)dbox_file_metadata_seek(file, metadata_offset, &expunged); + (void)dbox_file_metadata_seek_mail_offset(file, offset, + &expunged); dbox_sync_update_metadata(ctx, file, entry, seq); if ((ret = dbox_file_metadata_write_to(file, output)) < 0) break;
--- a/src/lib-storage/index/dbox/dbox-sync-rebuild.c Sat Nov 10 23:37:10 2007 +0200 +++ b/src/lib-storage/index/dbox/dbox-sync-rebuild.c Sat Nov 10 23:40:36 2007 +0200 @@ -144,7 +144,7 @@ struct dbox_file *file, uoff_t *offset) { uint32_t seq, uid; - uoff_t metadata_offset, physical_size; + uoff_t physical_size; const char *path; bool expunged; int ret; @@ -185,9 +185,7 @@ file->last_append_uid = uid; } - metadata_offset = - dbox_file_get_metadata_offset(file, *offset, physical_size); - ret = dbox_file_metadata_seek(file, metadata_offset, &expunged); + ret = dbox_file_metadata_seek_mail_offset(file, *offset, &expunged); if (ret <= 0) { if (ret < 0) return -1; @@ -318,6 +316,8 @@ int ret = 0; fnames = array_get(&ctx->maildir_new_files, &count); + if (count == 0) + return 0; /* try to give them UIDs beginning from uidlist's next_uid */ next_uid = maildir_uidlist_get_next_uid(ctx->maildir_uidlist);
--- a/src/lib-storage/index/maildir/maildir-keywords.c Sat Nov 10 23:37:10 2007 +0200 +++ b/src/lib-storage/index/maildir/maildir-keywords.c Sat Nov 10 23:40:36 2007 +0200 @@ -346,7 +346,7 @@ mk->synced = FALSE; - if (!mk->changed) + if (!mk->changed || mk->mbox == NULL) return 0; /* we could just create the temp file directly, but doing it this