]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Moved common code to index_storage_save_continue()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 10 May 2016 21:06:54 +0000 (17:06 -0400)
committerGitLab <gitlab@git.dovecot.net>
Thu, 12 May 2016 22:07:36 +0000 (01:07 +0300)
src/lib-storage/index/cydir/cydir-save.c
src/lib-storage/index/dbox-common/dbox-save.c
src/lib-storage/index/imapc/imapc-save.c
src/lib-storage/index/index-storage.c
src/lib-storage/index/index-storage.h
src/lib-storage/index/maildir/maildir-save.c

index cc964cd9b030a2ac43e448260167b520ccce4368..0131521ef01e8d72eaf6cabbd8b0e0cc7ed79d2c 100644 (file)
@@ -91,6 +91,7 @@ int cydir_save_begin(struct mail_save_context *_ctx, struct istream *input)
                if (ctx->fd != -1) {
                        _ctx->data.output =
                                o_stream_create_fd_file(ctx->fd, 0, FALSE);
+                       o_stream_set_name(_ctx->data.output, path);
                        o_stream_cork(_ctx->data.output);
                } else {
                        mail_storage_set_critical(trans->box->storage,
@@ -131,27 +132,15 @@ int cydir_save_begin(struct mail_save_context *_ctx, struct istream *input)
 int cydir_save_continue(struct mail_save_context *_ctx)
 {
        struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
-       struct mail_storage *storage = &ctx->mbox->storage->storage;
 
        if (ctx->failed)
                return -1;
 
-       do {
-               if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
-                       if (!mail_storage_set_error_from_errno(storage)) {
-                               mail_storage_set_critical(storage,
-                                       "write(%s) failed: %m",
-                                       cydir_get_save_path(ctx, ctx->mail_count));
-                       }
-                       ctx->failed = TRUE;
-                       return -1;
-               }
-               index_mail_cache_parse_continue(_ctx->dest_mail);
-
-               /* both tee input readers may consume data from our primary
-                  input stream. we'll have to make sure we don't return with
-                  one of the streams still having data in them. */
-       } while (i_stream_read(ctx->input) > 0);
+       if (index_storage_save_continue(_ctx, ctx->input,
+                                       _ctx->dest_mail) < 0) {
+               ctx->failed = TRUE;
+               return -1;
+       }
        return 0;
 }
 
index fe305a6df894ab5b11801e1b71afbf7f3bf2400e..c62973874cdfc53c59b7406a91b48444a6bed119 100644 (file)
@@ -7,6 +7,7 @@
 #include "str.h"
 #include "hex-binary.h"
 #include "index-mail.h"
+#include "index-storage.h"
 #include "dbox-attachment.h"
 #include "dbox-file.h"
 #include "dbox-save.h"
@@ -70,7 +71,6 @@ void dbox_save_begin(struct dbox_save_context *ctx, struct istream *input)
 int dbox_save_continue(struct mail_save_context *_ctx)
 {
        struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
-       struct mail_storage *storage = _ctx->transaction->box->storage;
 
        if (ctx->failed)
                return -1;
@@ -78,22 +78,11 @@ int dbox_save_continue(struct mail_save_context *_ctx)
        if (_ctx->data.attach != NULL)
                return index_attachment_save_continue(_ctx);
 
-       do {
-               if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
-                       if (!mail_storage_set_error_from_errno(storage)) {
-                               mail_storage_set_critical(storage,
-                                       "write(%s) failed: %m",
-                                       o_stream_get_name(_ctx->data.output));
-                       }
-                       ctx->failed = TRUE;
-                       return -1;
-               }
-               index_mail_cache_parse_continue(_ctx->dest_mail);
-
-               /* both tee input readers may consume data from our primary
-                  input stream. we'll have to make sure we don't return with
-                  one of the streams still having data in them. */
-       } while (i_stream_read(ctx->input) > 0);
+       if (index_storage_save_continue(_ctx, ctx->input,
+                                       _ctx->dest_mail) < 0) {
+               ctx->failed = TRUE;
+               return -1;
+       }
        return 0;
 }
 
index e6012ff8d8e3303075b0918c527d533cee700a53..ff9e23b228d34e9aabc0b229055e3d7d6d722a1b 100644 (file)
@@ -89,17 +89,11 @@ int imapc_save_begin(struct mail_save_context *_ctx, struct istream *input)
 int imapc_save_continue(struct mail_save_context *_ctx)
 {
        struct imapc_save_context *ctx = (struct imapc_save_context *)_ctx;
-       struct mail_storage *storage = _ctx->transaction->box->storage;
 
        if (ctx->failed)
                return -1;
 
-       if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
-               if (!mail_storage_set_error_from_errno(storage)) {
-                       mail_storage_set_critical(storage,
-                               "o_stream_send_istream(%s) failed: %m",
-                               ctx->temp_path);
-               }
+       if (index_storage_save_continue(_ctx, ctx->input, NULL) < 0) {
                ctx->failed = TRUE;
                return -1;
        }
index b4fbe858d015bc670eec388511494baeb3eae8c1..e94b82a3e14e789bc86b8be59f9bab5b6c4a2026 100644 (file)
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "array.h"
 #include "istream.h"
+#include "ostream.h"
 #include "ioloop.h"
 #include "str.h"
 #include "mkdir-parents.h"
@@ -1016,3 +1017,28 @@ int index_storage_expunged_sync_begin(struct mailbox *box,
        }
        return 1;
 }
+
+int index_storage_save_continue(struct mail_save_context *ctx,
+                               struct istream *input,
+                               struct mail *cache_dest_mail)
+{
+       struct mail_storage *storage = ctx->transaction->box->storage;
+
+       do {
+               if (o_stream_send_istream(ctx->data.output, input) < 0) {
+                       if (!mail_storage_set_error_from_errno(storage)) {
+                               mail_storage_set_critical(storage,
+                                       "write(%s) failed: %m",
+                                       o_stream_get_name(ctx->data.output));
+                       }
+                       return -1;
+               }
+               if (cache_dest_mail != NULL)
+                       index_mail_cache_parse_continue(cache_dest_mail);
+
+               /* both tee input readers may consume data from our primary
+                  input stream. we'll have to make sure we don't return with
+                  one of the streams still having data in them. */
+       } while (i_stream_read(input) > 0);
+       return 0;
+}
index be43e1d78c3ea030cb325810380b9d556d4a50c8..277cef094bdd544402bbb86e3eb6db1cefc69080 100644 (file)
@@ -180,4 +180,8 @@ int index_storage_expunged_sync_begin(struct mailbox *box,
                                      enum mail_index_sync_flags flags);
 void index_storage_expunging_deinit(struct mailbox *box);
 
+int index_storage_save_continue(struct mail_save_context *ctx,
+                               struct istream *input,
+                               struct mail *cache_dest_mail);
+
 #endif
index 228c272142577d0beabca102764db24dd4da7047..8999737a9d02cce02d3df95bfdcc15b0e4c59bd4 100644 (file)
@@ -440,6 +440,8 @@ int maildir_save_begin(struct mail_save_context *_ctx, struct istream *input)
 
        if (!ctx->failed) {
                _ctx->data.output = o_stream_create_fd_file(ctx->fd, 0, FALSE);
+               o_stream_set_name(_ctx->data.output, t_strdup_printf(
+                       "%s/%s", ctx->tmpdir, ctx->file_last->tmp_name));
                o_stream_cork(_ctx->data.output);
                ctx->last_save_finished = FALSE;
        }
@@ -449,29 +451,15 @@ int maildir_save_begin(struct mail_save_context *_ctx, struct istream *input)
 int maildir_save_continue(struct mail_save_context *_ctx)
 {
        struct maildir_save_context *ctx = (struct maildir_save_context *)_ctx;
-       struct mail_storage *storage = &ctx->mbox->storage->storage;
 
        if (ctx->failed)
                return -1;
 
-       do {
-               if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
-                       if (!mail_storage_set_error_from_errno(storage)) {
-                               mail_storage_set_critical(storage,
-                                       "o_stream_send_istream(%s/%s) "
-                                       "failed: %m",
-                                       ctx->tmpdir, ctx->file_last->tmp_name);
-                       }
-                       ctx->failed = TRUE;
-                       return -1;
-               }
-               if (ctx->cur_dest_mail != NULL)
-                       index_mail_cache_parse_continue(ctx->cur_dest_mail);
-
-               /* both tee input readers may consume data from our primary
-                  input stream. we'll have to make sure we don't return with
-                  one of the streams still having data in them. */
-       } while (i_stream_read(ctx->input) > 0);
+       if (index_storage_save_continue(_ctx, ctx->input,
+                                       ctx->cur_dest_mail) < 0) {
+               ctx->failed = TRUE;
+               return -1;
+       }
        return 0;
 }