]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox: Split dbox_file_seek() from dbox_file_get_mail_stream()
authorTimo Sirainen <tss@iki.fi>
Thu, 15 Jul 2010 15:59:11 +0000 (16:59 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 15 Jul 2010 15:59:11 +0000 (16:59 +0100)
src/lib-storage/index/dbox-common/dbox-file.c
src/lib-storage/index/dbox-common/dbox-file.h
src/lib-storage/index/dbox-common/dbox-mail.c
src/lib-storage/index/dbox-multi/mdbox-purge.c
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c

index 58fa3a9e4d173ef15fe46611b17d856fde44a466..dc5525d44351d48766407af23e11515afb0002b1 100644 (file)
@@ -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;
index 316610b15828234b8089f657991d0b7539b9ee00..26415b4dee089b3357f3be94defaf1148b31724a 100644 (file)
@@ -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. */
index 3eb04b33928dd85a849da3c10bf3a5b6fa661360..7ce2a7badfd0aca86fee8806599f3cb5e0b4bb7d 100644 (file)
@@ -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;
index 440a501aba053c14442c9cd728ff2f516c3bb67c..ea0f9911831622210e4b9acb0d5fac872a6236bb 100644 (file)
@@ -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) {
index a4d50542302848a7e0bf17cb19d9b0cf5e4e0725..58c35252b8c0ca846d98d07831826ee6f9648eee 100644 (file)
@@ -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);
index ba94e812bb2db1c3aceb8b3ff419815dcf9a93a8..4a02da98886d8419cce196ea0e56bf16cbe9c630 100644 (file)
@@ -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) {