annotate src/lib-storage/index/cydir/cydir-save.c @ 6083:1b0ef7a74448 HEAD

Moved tee stream handling to index-mail code.
author Timo Sirainen <tss@iki.fi>
date Wed, 18 Jul 2007 09:36:22 +0300
parents d911d943438e
children 6c0bfc35af03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2007 Timo Sirainen */
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "hostpid.h"
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "istream.h"
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "ostream.h"
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "ostream-crlf.h"
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "str.h"
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "index-mail.h"
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "cydir-storage.h"
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "cydir-sync.h"
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include <stdio.h>
5628
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
14 #include <utime.h>
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 struct cydir_save_context {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 struct mail_save_context ctx;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 struct cydir_mailbox *mbox;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 struct mail_index_transaction *trans;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 char *tmp_basename;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 unsigned int mail_count;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 struct cydir_sync_context *sync_ctx;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 /* updated for each appended mail: */
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 uint32_t seq;
6083
1b0ef7a74448 Moved tee stream handling to index-mail code.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
29 struct istream *input;
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 struct ostream *output;
5629
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
31 struct mail *mail, *cur_dest_mail;
5628
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
32 int fd;
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 unsigned int failed:1;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 unsigned int finished:1;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 };
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 static char *cydir_generate_tmp_filename(void)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 static unsigned int create_count;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 return i_strdup_printf("%s.P%sQ%uM%s.%s",
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 dec2str(ioloop_timeval.tv_sec), my_pid,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 create_count++,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 dec2str(ioloop_timeval.tv_usec), my_hostname);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 static const char *
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 cydir_get_save_path(struct cydir_save_context *ctx, unsigned int num)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 const char *dir;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52
5459
78eaf595359c Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents: 5458
diff changeset
53 dir = mailbox_list_get_path(ctx->mbox->storage->storage.list,
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 ctx->mbox->ibox.box.name,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 MAILBOX_LIST_PATH_TYPE_MAILBOX);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 return t_strdup_printf("%s/%s.%u", dir, ctx->tmp_basename, num);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 int cydir_save_init(struct mailbox_transaction_context *_t,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 enum mail_flags flags, struct mail_keywords *keywords,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 time_t received_date, int timezone_offset __attr_unused__,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 const char *from_envelope __attr_unused__,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 struct istream *input, struct mail *dest_mail,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 struct mail_save_context **ctx_r)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 struct cydir_transaction_context *t =
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 (struct cydir_transaction_context *)_t;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 struct cydir_mailbox *mbox = (struct cydir_mailbox *)t->ictx.ibox;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 struct cydir_save_context *ctx = t->save_ctx;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 enum mail_flags save_flags;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 struct ostream *output;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 const char *path;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 if (ctx == NULL) {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 ctx = t->save_ctx = i_new(struct cydir_save_context, 1);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 ctx->ctx.transaction = &t->ictx.mailbox_ctx;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 ctx->mbox = mbox;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 ctx->trans = t->ictx.trans;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 ctx->tmp_basename = cydir_generate_tmp_filename();
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 t_push();
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 path = cydir_get_save_path(ctx, ctx->mail_count);
5628
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
86 ctx->fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0660);
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
87 if (ctx->fd != -1) {
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
88 output = o_stream_create_file(ctx->fd, default_pool, 0, FALSE);
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 ctx->output = o_stream_create_crlf(default_pool, output);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 o_stream_unref(&output);
5628
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
91
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
92 if (received_date != (time_t)-1) {
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
93 struct utimbuf ut;
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
94
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
95 ut.actime = ioloop_time;
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
96 ut.modtime = received_date;
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
97 if (utime(path, &ut) < 0) {
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
98 mail_storage_set_critical(_t->box->storage,
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
99 "utime(%s) failed: %m", path);
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
100 /* ignore this error anyway */
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
101 }
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
102 }
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 } else {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 mail_storage_set_critical(_t->box->storage,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 "open(%s) failed: %m", path);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 ctx->failed = TRUE;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 t_pop();
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 return -1;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 t_pop();
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 /* add to index */
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 5963
diff changeset
113 save_flags = flags & ~MAIL_RECENT;
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114 mail_index_append(ctx->trans, 0, &ctx->seq);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 mail_index_update_flags(ctx->trans, ctx->seq, MODIFY_REPLACE,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 save_flags);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 if (keywords != NULL) {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 mail_index_update_keywords(ctx->trans, ctx->seq,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 MODIFY_REPLACE, keywords);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122 if (dest_mail == NULL) {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123 if (ctx->mail == NULL)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 ctx->mail = index_mail_alloc(_t, 0, NULL);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 dest_mail = ctx->mail;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 if (mail_set_seq(dest_mail, ctx->seq) < 0)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128 i_unreached();
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129
5629
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
130 ctx->cur_dest_mail = dest_mail;
6083
1b0ef7a74448 Moved tee stream handling to index-mail code.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
131 ctx->input = index_mail_cache_parse_init(dest_mail, input);
5629
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
132
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 *ctx_r = &ctx->ctx;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134 return ctx->failed ? -1 : 0;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 int cydir_save_continue(struct mail_save_context *_ctx)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139 struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5573
diff changeset
140 struct mail_storage *storage = &ctx->mbox->storage->storage;
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 if (ctx->failed)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 return -1;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144
5963
9bef18690777 Cache updater might not have seen all the input data producing broken data.
Timo Sirainen <tss@iki.fi>
parents: 5629
diff changeset
145 do {
9bef18690777 Cache updater might not have seen all the input data producing broken data.
Timo Sirainen <tss@iki.fi>
parents: 5629
diff changeset
146 if (o_stream_send_istream(ctx->output, ctx->input) < 0) {
9bef18690777 Cache updater might not have seen all the input data producing broken data.
Timo Sirainen <tss@iki.fi>
parents: 5629
diff changeset
147 if (!mail_storage_set_error_from_errno(storage)) {
9bef18690777 Cache updater might not have seen all the input data producing broken data.
Timo Sirainen <tss@iki.fi>
parents: 5629
diff changeset
148 mail_storage_set_critical(storage,
9bef18690777 Cache updater might not have seen all the input data producing broken data.
Timo Sirainen <tss@iki.fi>
parents: 5629
diff changeset
149 "o_stream_send_istream(%s) failed: %m",
9bef18690777 Cache updater might not have seen all the input data producing broken data.
Timo Sirainen <tss@iki.fi>
parents: 5629
diff changeset
150 cydir_get_save_path(ctx, ctx->mail_count));
9bef18690777 Cache updater might not have seen all the input data producing broken data.
Timo Sirainen <tss@iki.fi>
parents: 5629
diff changeset
151 }
9bef18690777 Cache updater might not have seen all the input data producing broken data.
Timo Sirainen <tss@iki.fi>
parents: 5629
diff changeset
152 ctx->failed = TRUE;
9bef18690777 Cache updater might not have seen all the input data producing broken data.
Timo Sirainen <tss@iki.fi>
parents: 5629
diff changeset
153 return -1;
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 }
6083
1b0ef7a74448 Moved tee stream handling to index-mail code.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
155 index_mail_cache_parse_continue(ctx->cur_dest_mail);
1b0ef7a74448 Moved tee stream handling to index-mail code.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
156
1b0ef7a74448 Moved tee stream handling to index-mail code.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
157 /* both tee input readers may consume data from our primary
1b0ef7a74448 Moved tee stream handling to index-mail code.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
158 input stream. we'll have to make sure we don't return with
1b0ef7a74448 Moved tee stream handling to index-mail code.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
159 one of the streams still having data in them. */
1b0ef7a74448 Moved tee stream handling to index-mail code.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
160 } while (i_stream_read(ctx->input) > 0);
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 return 0;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 int cydir_save_finish(struct mail_save_context *_ctx)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
5628
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
167 struct mail_storage *storage = &ctx->mbox->storage->storage;
5629
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
168 const char *path = cydir_get_save_path(ctx, ctx->mail_count);
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 ctx->finished = TRUE;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171
5628
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
172 if (!ctx->mbox->ibox.fsync_disable) {
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
173 if (fsync(ctx->fd) < 0) {
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
174 mail_storage_set_critical(storage,
5629
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
175 "fsync(%s) failed: %m", path);
5628
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
176 ctx->failed = TRUE;
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
177 }
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
178 }
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
179
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
180 o_stream_destroy(&ctx->output);
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
181 if (close(ctx->fd) < 0) {
5629
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
182 mail_storage_set_critical(storage,
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
183 "close(%s) failed: %m", path);
5628
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
184 ctx->failed = TRUE;
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
185 }
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
186 ctx->fd = -1;
950d7af6ed14 Don't leak memory and file descriptors in appends. fsync() unless it's
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
187
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 if (!ctx->failed)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 ctx->mail_count++;
5629
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
190 else {
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
191 if (unlink(path) < 0) {
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
192 mail_storage_set_critical(storage,
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
193 "unlink(%s) failed: %m", path);
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
194 }
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
195 }
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
196
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
197 index_mail_cache_parse_deinit(ctx->cur_dest_mail);
6b06a60d7e44 If saving is aborted, don't leave temporary files lying around. Update cache
Timo Sirainen <tss@iki.fi>
parents: 5628
diff changeset
198 i_stream_unref(&ctx->input);
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200 return ctx->failed ? -1 : 0;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
202
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203 void cydir_save_cancel(struct mail_save_context *_ctx)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
204 {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205 struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207 ctx->failed = TRUE;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
208 (void)cydir_save_finish(_ctx);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
210
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
211 int cydir_transaction_save_commit_pre(struct cydir_save_context *ctx)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
212 {
5572
896845fbc4ed Added mailbox_transaction_commit_get_uids() which returns the UID range for
Timo Sirainen <tss@iki.fi>
parents: 5484
diff changeset
213 struct cydir_transaction_context *t =
896845fbc4ed Added mailbox_transaction_commit_get_uids() which returns the UID range for
Timo Sirainen <tss@iki.fi>
parents: 5484
diff changeset
214 (struct cydir_transaction_context *)ctx->ctx.transaction;
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 const struct mail_index_header *hdr;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216 uint32_t i, uid, next_uid;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217 const char *dir;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 string_t *src_path, *dest_path;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219 unsigned int src_prefixlen, dest_prefixlen;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
220
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
221 i_assert(ctx->finished);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
222
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
223 if (cydir_sync_begin(ctx->mbox, &ctx->sync_ctx) < 0) {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
224 ctx->failed = TRUE;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
225 cydir_transaction_save_rollback(ctx);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
226 return -1;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
227 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
228
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
229 hdr = mail_index_get_header(ctx->sync_ctx->sync_view);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230 uid = hdr->next_uid;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 mail_index_append_assign_uids(ctx->trans, uid, &next_uid);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232
5573
9805becea644 Fixed mailbox_transaction_commit_get_uids() to actually work and not just
Timo Sirainen <tss@iki.fi>
parents: 5572
diff changeset
233 *t->ictx.first_saved_uid = uid;
9805becea644 Fixed mailbox_transaction_commit_get_uids() to actually work and not just
Timo Sirainen <tss@iki.fi>
parents: 5572
diff changeset
234 *t->ictx.last_saved_uid = next_uid - 1;
5572
896845fbc4ed Added mailbox_transaction_commit_get_uids() which returns the UID range for
Timo Sirainen <tss@iki.fi>
parents: 5484
diff changeset
235
5459
78eaf595359c Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents: 5458
diff changeset
236 dir = mailbox_list_get_path(ctx->mbox->storage->storage.list,
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237 ctx->mbox->ibox.box.name,
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
238 MAILBOX_LIST_PATH_TYPE_MAILBOX);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
240 src_path = t_str_new(256);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
241 str_printfa(src_path, "%s/%s.", dir, ctx->tmp_basename);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
242 src_prefixlen = str_len(src_path);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
243
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
244 dest_path = t_str_new(256);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245 str_append(dest_path, dir);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
246 str_append_c(dest_path, '/');
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
247 dest_prefixlen = str_len(dest_path);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
248
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
249 for (i = 0; i < ctx->mail_count; i++, uid++) {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 str_truncate(src_path, src_prefixlen);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
251 str_truncate(dest_path, dest_prefixlen);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252 str_printfa(src_path, "%u", i);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 str_printfa(dest_path, "%u.", uid);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
255 if (rename(str_c(src_path), str_c(dest_path)) < 0) {
5459
78eaf595359c Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents: 5458
diff changeset
256 mail_storage_set_critical(&ctx->mbox->storage->storage,
5458
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257 "rename(%s, %s) failed: %m",
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
258 str_c(src_path), str_c(dest_path));
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
259 ctx->failed = TRUE;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
260 cydir_transaction_save_rollback(ctx);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
261 return -1;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
262 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
263 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
264
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 return 0;
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
267
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
268 void cydir_transaction_save_commit_post(struct cydir_save_context *ctx)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269 {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
270 (void)cydir_sync_finish(&ctx->sync_ctx, TRUE);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
271 cydir_transaction_save_rollback(ctx);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
272 }
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 void cydir_transaction_save_rollback(struct cydir_save_context *ctx)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
275 {
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 if (!ctx->finished)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 cydir_save_cancel(&ctx->ctx);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
279 if (ctx->sync_ctx != NULL)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
280 (void)cydir_sync_finish(&ctx->sync_ctx, FALSE);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282 if (ctx->mail != NULL)
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
283 index_mail_free(ctx->mail);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
284 i_free(ctx->tmp_basename);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
285 i_free(ctx);
daca7ed634c0 Added a simple cydir mail storage backend. It trusts index files completely:
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
286 }