From: Timo Sirainen Date: Thu, 15 Jul 2010 15:59:11 +0000 (+0100) Subject: dbox: Split dbox_file_seek() from dbox_file_get_mail_stream() X-Git-Tag: 2.0.rc3~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a81b240cfe84231eac64084efd5b0e1e91a9e817;p=thirdparty%2Fdovecot%2Fcore.git dbox: Split dbox_file_seek() from dbox_file_get_mail_stream() --- diff --git a/src/lib-storage/index/dbox-common/dbox-file.c b/src/lib-storage/index/dbox-common/dbox-file.c index 58fa3a9e4d..dc5525d443 100644 --- a/src/lib-storage/index/dbox-common/dbox-file.c +++ b/src/lib-storage/index/dbox-common/dbox-file.c @@ -367,8 +367,7 @@ int dbox_file_read_mail_header(struct dbox_file *file, uoff_t *physical_size_r) return 1; } -int dbox_file_get_mail_stream(struct dbox_file *file, uoff_t offset, - struct istream **stream_r) +int dbox_file_seek(struct dbox_file *file, uoff_t offset) { uoff_t size; int ret; @@ -387,10 +386,18 @@ int dbox_file_get_mail_stream(struct dbox_file *file, uoff_t offset, file->cur_physical_size = size; } i_stream_seek(file->input, offset + file->msg_header_size); - if (stream_r != NULL) { - *stream_r = i_stream_create_limit(file->input, - file->cur_physical_size); - } + return 1; +} + +int dbox_file_get_mail_stream(struct dbox_file *file, uoff_t offset, + struct istream **stream_r) +{ + int ret; + + if ((ret = dbox_file_seek(file, offset)) <= 0) + return ret; + + *stream_r = i_stream_create_limit(file->input, file->cur_physical_size); return 1; } @@ -447,7 +454,7 @@ int dbox_file_seek_next(struct dbox_file *file, uoff_t *offset_r, bool *last_r) } *last_r = FALSE; - ret = dbox_file_get_mail_stream(file, offset, NULL); + ret = dbox_file_seek(file, offset); if (*offset_r == 0) *offset_r = file->file_header_size; return ret; diff --git a/src/lib-storage/index/dbox-common/dbox-file.h b/src/lib-storage/index/dbox-common/dbox-file.h index 316610b158..26415b4dee 100644 --- a/src/lib-storage/index/dbox-common/dbox-file.h +++ b/src/lib-storage/index/dbox-common/dbox-file.h @@ -153,8 +153,10 @@ int dbox_file_stat(struct dbox_file *file, struct stat *st_r); int dbox_file_try_lock(struct dbox_file *file); void dbox_file_unlock(struct dbox_file *file); -/* Seek to given offset in file and return the message's input stream. - Returns 1 if ok/expunged, 0 if file/offset is corrupted, -1 if I/O error. */ +/* Seek to given offset in file. Returns 1 if ok/expunged, 0 if file/offset is + corrupted, -1 if I/O error. */ +int dbox_file_seek(struct dbox_file *file, uoff_t offset); +/* Same as dbox_file_seek(), but return also input stream for message. */ int dbox_file_get_mail_stream(struct dbox_file *file, uoff_t offset, struct istream **input_r); /* Start seeking at the beginning of the file. */ diff --git a/src/lib-storage/index/dbox-common/dbox-mail.c b/src/lib-storage/index/dbox-common/dbox-mail.c index 3eb04b3392..7ce2a7badf 100644 --- a/src/lib-storage/index/dbox-common/dbox-mail.c +++ b/src/lib-storage/index/dbox-common/dbox-mail.c @@ -45,7 +45,7 @@ int dbox_mail_metadata_read(struct dbox_mail *mail, struct dbox_file **file_r) if (storage->v.mail_open(mail, &offset, file_r) < 0) return -1; - if (dbox_file_get_mail_stream(*file_r, offset, NULL) <= 0) + if (dbox_file_seek(*file_r, offset) <= 0) return -1; if (dbox_file_metadata_read(*file_r) <= 0) return -1; diff --git a/src/lib-storage/index/dbox-multi/mdbox-purge.c b/src/lib-storage/index/dbox-multi/mdbox-purge.c index 440a501aba..ea0f991183 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-purge.c +++ b/src/lib-storage/index/dbox-multi/mdbox-purge.c @@ -229,7 +229,7 @@ mdbox_file_purge(struct mdbox_purge_context *ctx, struct dbox_file *file) i_array_init(&expunged_map_uids, I_MIN(count, 1)); offset = file->file_header_size; for (i = 0; i < count; i++) { - if ((ret = dbox_file_get_mail_stream(file, offset, NULL)) <= 0) + if ((ret = dbox_file_seek(file, offset)) <= 0) break; if (msgs[i].offset != offset) { diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c index a4d5054230..58c35252b8 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c @@ -175,8 +175,7 @@ static int rebuild_file_mails(struct mdbox_storage_rebuild_context *ctx, fixed = TRUE; if (!first) { /* seek to the offset where we last left off */ - ret = dbox_file_get_mail_stream(file, - prev_offset, NULL); + ret = dbox_file_seek(file, prev_offset); if (ret <= 0) break; } @@ -613,7 +612,7 @@ static int rebuild_restore_msg(struct mdbox_storage_rebuild_context *ctx, file = mdbox_file_init(ctx->storage, msg->file_id); ret = dbox_file_open(file, &deleted); if (ret > 0 && !deleted) - ret = dbox_file_get_mail_stream(file, msg->offset, NULL); + ret = dbox_file_seek(file, msg->offset); if (ret > 0 && !deleted && dbox_file_metadata_read(file) > 0) { mailbox = dbox_file_metadata_get(file, DBOX_METADATA_ORIG_MAILBOX); diff --git a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c index ba94e812bb..4a02da9888 100644 --- a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c +++ b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c @@ -34,11 +34,11 @@ static int sdbox_sync_add_file_index(struct dbox_sync_rebuild_context *ctx, if ((ret = dbox_file_open(file, &deleted)) > 0) { if (deleted) return 0; - ret = dbox_file_get_mail_stream(file, 0, NULL); + ret = dbox_file_seek(file, 0); } if (ret == 0) { if ((ret = dbox_file_fix(file, 0)) == 0) - ret = dbox_file_get_mail_stream(file, 0, NULL); + ret = dbox_file_seek(file, 0); } if (ret <= 0) {