Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/maildir/maildir-sync.c @ 2322:aae574ed7f4c HEAD
Broke mailbox_sync() into iterator.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 12 Jul 2004 14:35:50 +0300 |
parents | 8a6666a9ac98 |
children | 9c830d1a4ebf |
rev | line source |
---|---|
1955 | 1 /* Copyright (C) 2004 Timo Sirainen */ |
2 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 /* |
1955 | 4 Here's a description of how we handle Maildir synchronization and |
5 it's problems: | |
6 | |
7 We want to be as efficient as we can. The most efficient way to | |
8 check if changes have occured is to stat() the new/ and cur/ | |
9 directories and uidlist file - if their mtimes haven't changed, | |
10 there's no changes and we don't need to do anything. | |
11 | |
12 Problem 1: Multiple changes can happen within a single second - | |
13 nothing guarantees that once we synced it, someone else didn't just | |
14 then make a modification. Such modifications wouldn't get noticed | |
15 until a new modification occured later. | |
16 | |
17 Problem 2: Syncing cur/ directory is much more costly than syncing | |
18 new/. Moving mails from new/ to cur/ will always change mtime of | |
19 cur/ causing us to sync it as well. | |
20 | |
21 Problem 3: We may not be able to move mail from new/ to cur/ | |
22 because we're out of quota, or simply because we're accessing a | |
23 read-only mailbox. | |
24 | |
25 | |
26 MAILDIR_SYNC_SECS | |
27 ----------------- | |
28 | |
29 Several checks below use MAILDIR_SYNC_SECS, which should be maximum | |
30 clock drift between all computers accessing the maildir (eg. via | |
31 NFS), rounded up to next second. Our default is 1 second, since | |
32 everyone should be using NTP. | |
33 | |
34 Note that setting it to 0 works only if there's only one computer | |
35 accessing the maildir. It's practically impossible to make two | |
36 clocks _exactly_ synchronized. | |
37 | |
38 It might be possible to only use file server's clock by looking at | |
39 the atime field, but I don't know how well that would actually work. | |
40 | |
41 cur directory | |
42 ------------- | |
43 | |
44 We have dirty_cur_time variable which is set to cur/ directory's | |
45 mtime when it's >= time() - MAILDIR_SYNC_SECS and we _think_ we have | |
46 synchronized the directory. | |
47 | |
48 When dirty_cur_time is non-zero, we don't synchronize the cur/ | |
49 directory until | |
50 | |
51 a) cur/'s mtime changes | |
52 b) opening a mail fails with ENOENT | |
53 c) time() > dirty_cur_time + MAILDIR_SYNC_SECS | |
54 | |
55 This allows us to modify the maildir multiple times without having | |
56 to sync it at every change. The sync will eventually be done to | |
57 make sure we didn't miss any external changes. | |
58 | |
59 The dirty_cur_time is set when: | |
60 | |
61 - we change message flags | |
62 - we expunge messages | |
63 - we move mail from new/ to cur/ | |
64 - we sync cur/ directory and it's mtime is >= time() - MAILDIR_SYNC_SECS | |
65 | |
66 It's unset when we do the final syncing, ie. when mtime is | |
67 older than time() - MAILDIR_SYNC_SECS. | |
68 | |
69 new directory | |
70 ------------- | |
71 | |
72 If new/'s mtime is >= time() - MAILDIR_SYNC_SECS, always synchronize | |
73 it. dirty_cur_time-like feature might save us a few syncs, but | |
74 that might break a client which saves a mail in one connection and | |
75 tries to fetch it in another one. new/ directory is almost always | |
76 empty, so syncing it should be very fast anyway. Actually this can | |
77 still happen if we sync only new/ dir while another client is also | |
78 moving mails from it to cur/ - it takes us a while to see them. | |
79 That's pretty unlikely to happen however, and only way to fix it | |
80 would be to always synchronize cur/ after new/. | |
81 | |
82 Normally we move all mails from new/ to cur/ whenever we sync it. If | |
83 it's not possible for some reason, we mark the mail with "probably | |
84 exists in new/ directory" flag. | |
85 | |
86 If rename() still fails because of ENOSPC or EDQUOT, we still save | |
87 the flag changes in index with dirty-flag on. When moving the mail | |
88 to cur/ directory, or when we notice it's already moved there, we | |
89 apply the flag changes to the filename, rename it and remove the | |
90 dirty flag. If there's dirty flags, this should be tried every time | |
91 after expunge or when closing the mailbox. | |
92 | |
93 uidlist | |
94 ------- | |
95 | |
96 This file contains UID <-> filename mappings. It's updated only when | |
97 new mail arrives, so it may contain filenames that have already been | |
98 deleted. Updating is done by getting uidlist.lock file, writing the | |
99 whole uidlist into it and rename()ing it over the old uidlist. This | |
100 means there's no need to lock the file for reading. | |
101 | |
102 Whenever uidlist is rewritten, it's mtime must be larger than the old | |
103 one's. Use utime() before rename() if needed. Note that inode checking | |
104 wouldn't have been sufficient as inode numbers can be reused. | |
105 | |
106 This file is usually read the first time you need to know filename for | |
107 given UID. After that it's not re-read unless new mails come that we | |
108 don't know about. | |
109 | |
110 broken clients | |
111 -------------- | |
112 | |
113 Originally the middle identifier in Maildir filename was specified | |
114 only as <process id>_<delivery counter>. That however created a | |
115 problem with randomized PIDs which made it possible that the same | |
116 PID was reused within one second. | |
117 | |
118 So if within one second a mail was delivered, MUA moved it to cur/ | |
119 and another mail was delivered by a new process using same PID as | |
120 the first one, we likely ended up overwriting the first mail when | |
121 the second mail was moved over it. | |
122 | |
123 Nowadays everyone should be giving a bit more specific identifier, | |
124 for example include microseconds in it which Dovecot does. | |
125 | |
126 There's a simple way to prevent this from happening in some cases: | |
127 Don't move the mail from new/ to cur/ if it's mtime is >= time() - | |
128 MAILDIR_SYNC_SECS. The second delivery's link() call then fails | |
129 because the file is already in new/, and it will then use a | |
130 different filename. There's a few problems with this however: | |
131 | |
132 - it requires extra stat() call which is unneeded extra I/O | |
133 - another MUA might still move the mail to cur/ | |
134 - if first file's flags are modified by either Dovecot or another | |
135 MUA, it's moved to cur/ (you _could_ just do the dirty-flagging | |
136 but that'd be ugly) | |
137 | |
138 Because this is useful only for very few people and it requires | |
139 extra I/O, I decided not to implement this. It should be however | |
140 quite easy to do since we need to be able to deal with files in new/ | |
141 in any case. | |
142 | |
143 It's also possible to never accidentally overwrite a mail by using | |
144 link() + unlink() rather than rename(). This however isn't very | |
145 good idea as it introduces potential race conditions when multiple | |
146 clients are accessing the mailbox: | |
147 | |
148 Trying to move the same mail from new/ to cur/ at the same time: | |
149 | |
150 a) Client 1 uses slightly different filename than client 2, | |
151 for example one sets read-flag on but the other doesn't. | |
152 You have the same mail duplicated now. | |
153 | |
154 b) Client 3 sees the mail between Client 1's and 2's link() calls | |
155 and changes it's flag. You have the same mail duplicated now. | |
156 | |
157 And it gets worse when they're unlink()ing in cur/ directory: | |
158 | |
159 c) Client 1 changes mails's flag and client 2 changes it back | |
160 between 1's link() and unlink(). The mail is now expunged. | |
161 | |
162 d) If you try to deal with the duplicates by unlink()ing another | |
163 one of them, you might end up unlinking both of them. | |
164 | |
165 So, what should we do then if we notice a duplicate? First of all, | |
166 it might not be a duplicate at all, readdir() might have just | |
167 returned it twice because it was just renamed. What we should do is | |
168 create a completely new base name for it and rename() it to that. | |
169 If the call fails with ENOENT, it only means that it wasn't a | |
170 duplicate after all. | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 #include "lib.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 #include "ioloop.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 #include "buffer.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 #include "hash.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 #include "str.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 #include "maildir-storage.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 #include "maildir-uidlist.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
180 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 #include <stdio.h> |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
182 #include <stddef.h> |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 #include <unistd.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 #include <dirent.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 #include <sys/stat.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 #define MAILDIR_SYNC_SECS 1 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 #define MAILDIR_FILENAME_FLAG_FOUND 128 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 struct maildir_sync_context { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 struct index_mailbox *ibox; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 const char *new_dir, *cur_dir; |
1954 | 194 int partial; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 struct maildir_uidlist_sync_ctx *uidlist_sync_ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
199 struct maildir_index_sync_context { |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
200 struct index_mailbox *ibox; |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
201 struct mail_index_view *view; |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
202 struct mail_index_sync_ctx *sync_ctx; |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
203 struct mail_index_transaction *trans; |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
204 |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
205 struct mail_index_sync_rec sync_rec; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
206 uint32_t seq; |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
207 int dirty_state; |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
208 }; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
209 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 static int maildir_expunge(struct index_mailbox *ibox, const char *path, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 void *context __attr_unused__) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 { |
1955 | 213 if (unlink(path) == 0) { |
214 ibox->dirty_cur_time = ioloop_time; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
215 return 1; |
1955 | 216 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 if (errno == ENOENT) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 mail_storage_set_critical(ibox->box.storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 "unlink(%s) failed: %m", path); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 static int maildir_sync_flags(struct index_mailbox *ibox, const char *path, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 void *context) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 { |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
228 struct maildir_index_sync_context *ctx = context; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 const char *newpath; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 enum mail_flags flags; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 uint8_t flags8; |
1958 | 232 keywords_mask_t keywords; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
234 ctx->dirty_state = 0; |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
235 |
1958 | 236 (void)maildir_filename_get_flags(path, &flags, keywords); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 flags8 = flags; |
1958 | 239 mail_index_sync_flags_apply(&ctx->sync_rec, &flags8, keywords); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 |
1958 | 241 newpath = maildir_filename_set_flags(path, flags8, keywords); |
1955 | 242 if (rename(path, newpath) == 0) { |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
243 if ((flags8 & MAIL_INDEX_MAIL_FLAG_DIRTY) != 0) |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
244 ctx->dirty_state = -1; |
1955 | 245 ibox->dirty_cur_time = ioloop_time; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 return 1; |
1955 | 247 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 if (errno == ENOENT) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
251 if (ENOSPACE(errno) || errno == EACCES) { |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
252 memset(keywords, 0, sizeof(keywords)); |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
253 mail_index_update_flags(ctx->trans, ctx->seq, MODIFY_ADD, |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
254 MAIL_INDEX_MAIL_FLAG_DIRTY, keywords); |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
255 ctx->dirty_state = 1; |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
256 return 1; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
257 } |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
258 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 mail_storage_set_critical(ibox->box.storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
260 "rename(%s, %s) failed: %m", path, newpath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 static int maildir_sync_record(struct index_mailbox *ibox, |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
265 struct maildir_index_sync_context *ctx) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 { |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
267 struct mail_index_sync_rec *sync_rec = &ctx->sync_rec; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
268 struct mail_index_view *view = ctx->view; |
2033
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
269 uint32_t seq, seq1, seq2, uid; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
271 switch (sync_rec->type) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 case MAIL_INDEX_SYNC_TYPE_APPEND: |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 case MAIL_INDEX_SYNC_TYPE_EXPUNGE: |
2033
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
275 /* make it go through sequences to avoid looping through huge |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
276 holes in UID range */ |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
277 if (mail_index_lookup_uid_range(view, sync_rec->uid1, |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
278 sync_rec->uid2, |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
279 &seq1, &seq2) < 0) |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
280 return -1; |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
281 |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
282 if (seq1 == 0) |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
283 break; |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
284 |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
285 for (seq = seq1; seq <= seq2; seq++) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
286 if (mail_index_lookup_uid(view, seq, &uid) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 if (maildir_file_do(ibox, uid, maildir_expunge, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 NULL) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
290 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 case MAIL_INDEX_SYNC_TYPE_FLAGS: |
2033
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
294 if (mail_index_lookup_uid_range(view, sync_rec->uid1, |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
295 sync_rec->uid2, |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
296 &seq1, &seq2) < 0) |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
297 return -1; |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
298 |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
299 if (seq1 == 0) |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
300 break; |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
301 |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
302 for (ctx->seq = seq1; ctx->seq <= seq2; ctx->seq++) { |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
303 if (mail_index_lookup_uid(view, ctx->seq, &uid) < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
304 return -1; |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
305 if (maildir_file_do(ibox, uid, |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
306 maildir_sync_flags, ctx) < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 return -1; |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
308 if (ctx->dirty_state < 0) { |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
309 /* flag isn't dirty anymore */ |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
310 keywords_mask_t keywords; |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
311 |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
312 memset(keywords, 0, sizeof(keywords)); |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
313 mail_index_update_flags(ctx->trans, ctx->seq, |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
314 MODIFY_REMOVE, |
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
315 MAIL_INDEX_MAIL_FLAG_DIRTY, keywords); |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
316 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 int maildir_sync_last_commit(struct index_mailbox *ibox) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 { |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
326 struct maildir_index_sync_context ctx; |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
327 uint32_t seq; |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
328 uoff_t offset; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
329 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
330 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 if (ibox->commit_log_file_seq == 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
334 memset(&ctx, 0, sizeof(ctx)); |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
335 ctx.ibox = ibox; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
336 |
2173
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
337 ibox->syncing_commit = TRUE; |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
338 ret = mail_index_sync_begin(ibox->index, &ctx.sync_ctx, &ctx.view, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
339 ibox->commit_log_file_seq, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
340 ibox->commit_log_file_offset); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
341 if (ret > 0) { |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
342 ctx.trans = mail_index_transaction_begin(ctx.view, FALSE); |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
343 |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
344 while ((ret = mail_index_sync_next(ctx.sync_ctx, |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
345 &ctx.sync_rec)) > 0) { |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
346 if (maildir_sync_record(ibox, &ctx) < 0) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
347 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
348 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
349 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
350 } |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
351 if (mail_index_transaction_commit(ctx.trans, &seq, &offset) < 0) |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
352 ret = -1; |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
353 if (mail_index_sync_end(ctx.sync_ctx) < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
354 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
355 } |
2173
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
356 ibox->syncing_commit = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
357 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
358 if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
359 ibox->commit_log_file_seq = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 ibox->commit_log_file_offset = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
361 } else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
362 mail_storage_set_index_error(ibox); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
363 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
364 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
365 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
366 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
367 static struct maildir_sync_context * |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
368 maildir_sync_context_new(struct index_mailbox *ibox) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
369 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
370 struct maildir_sync_context *ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
371 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
372 ctx = t_new(struct maildir_sync_context, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
373 ctx->ibox = ibox; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 ctx->new_dir = t_strconcat(ibox->path, "/new", NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 ctx->cur_dir = t_strconcat(ibox->path, "/cur", NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
376 return ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
377 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
378 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
379 static void maildir_sync_deinit(struct maildir_sync_context *ctx) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
381 if (ctx->uidlist_sync_ctx != NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 (void)maildir_uidlist_sync_deinit(ctx->uidlist_sync_ctx); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
385 static int maildir_fix_duplicate(struct index_mailbox *ibox, const char *dir, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
386 const char *old_fname) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
387 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
388 const char *new_fname, *old_path, *new_path; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 int ret = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 t_push(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
393 old_path = t_strconcat(dir, "/", old_fname, NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
394 new_fname = maildir_generate_tmp_filename(&ioloop_timeval); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
395 new_path = t_strconcat(ibox->path, "/new/", new_fname, NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
396 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 if (rename(old_path, new_path) == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
398 i_warning("Fixed duplicate in %s: %s -> %s", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
399 ibox->path, old_fname, new_fname); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
400 } else if (errno != ENOENT) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
401 mail_storage_set_critical(ibox->box.storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
402 "rename(%s, %s) failed: %m", old_path, new_path); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
403 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
404 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 t_pop(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
406 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
407 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
408 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
409 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
410 static int maildir_scan_dir(struct maildir_sync_context *ctx, int new_dir) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 struct mail_storage *storage = ctx->ibox->box.storage; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
413 const char *dir; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
414 DIR *dirp; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
415 string_t *src, *dest; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
416 struct dirent *dp; |
1947 | 417 enum maildir_uidlist_rec_flag flags; |
418 int move_new, ret = 1; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
419 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
420 dir = new_dir ? ctx->new_dir : ctx->cur_dir; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
421 dirp = opendir(dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
422 if (dirp == NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
423 mail_storage_set_critical(storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
424 "opendir(%s) failed: %m", dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
425 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
426 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
427 |
2121 | 428 t_push(); |
429 src = t_str_new(1024); | |
430 dest = t_str_new(1024); | |
431 | |
2039
f0925b2271e1
Added pop3_mails_keep_recent option. Fixed recent assert crash.
Timo Sirainen <tss@iki.fi>
parents:
2038
diff
changeset
|
432 move_new = new_dir && !mailbox_is_readonly(&ctx->ibox->box) && |
f0925b2271e1
Added pop3_mails_keep_recent option. Fixed recent assert crash.
Timo Sirainen <tss@iki.fi>
parents:
2038
diff
changeset
|
433 !ctx->ibox->keep_recent; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
434 while ((dp = readdir(dirp)) != NULL) { |
2258
087a43e29492
No maildir filename checking after all.
Timo Sirainen <tss@iki.fi>
parents:
2256
diff
changeset
|
435 if (dp->d_name[0] == '.') |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
436 continue; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
437 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
438 ret = maildir_uidlist_sync_next_pre(ctx->uidlist_sync_ctx, |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
439 dp->d_name); |
1984 | 440 if (ret == 0) { |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
441 /* new file and we couldn't lock uidlist, check this |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
442 later in next sync. */ |
1984 | 443 if (new_dir) |
444 ctx->ibox->last_new_mtime = 0; | |
445 else | |
446 ctx->ibox->dirty_cur_time = ioloop_time; | |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
447 continue; |
1984 | 448 } |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
449 if (ret < 0) |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
450 break; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
451 |
1947 | 452 flags = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
453 if (move_new) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
454 str_truncate(src, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 str_truncate(dest, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
456 str_printfa(src, "%s/%s", ctx->new_dir, dp->d_name); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
457 str_printfa(dest, "%s/%s", ctx->cur_dir, dp->d_name); |
1970
0f4c4a043be1
When moving mails to cur/, we must add the ":2," part to filename.
Timo Sirainen <tss@iki.fi>
parents:
1962
diff
changeset
|
458 if (strchr(dp->d_name, ':') == NULL) |
0f4c4a043be1
When moving mails to cur/, we must add the ":2," part to filename.
Timo Sirainen <tss@iki.fi>
parents:
1962
diff
changeset
|
459 str_append(dest, ":2,"); |
1947 | 460 if (rename(str_c(src), str_c(dest)) == 0) { |
1984 | 461 /* we moved it - it's \Recent for us */ |
1955 | 462 ctx->ibox->dirty_cur_time = ioloop_time; |
1947 | 463 flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED | |
464 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
465 } else if (ENOTFOUND(errno)) { | |
466 /* someone else moved it already */ | |
467 flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 } else if (ENOSPACE(errno)) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 /* not enough disk space, leave here */ |
1947 | 470 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | |
471 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 move_new = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 } else { |
1947 | 474 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | |
475 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 mail_storage_set_critical(storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
477 "rename(%s, %s) failed: %m", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 str_c(src), str_c(dest)); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 } |
1947 | 480 } else if (new_dir) { |
481 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | | |
482 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
483 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
484 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
485 ret = maildir_uidlist_sync_next(ctx->uidlist_sync_ctx, |
1947 | 486 dp->d_name, flags); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
487 if (ret <= 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
488 if (ret < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
489 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
490 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
491 /* possibly duplicate - try fixing it */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
492 if (maildir_fix_duplicate(ctx->ibox, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
493 dir, dp->d_name) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
494 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
495 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
496 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
497 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
498 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
499 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 if (closedir(dirp) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 mail_storage_set_critical(storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
502 "closedir(%s) failed: %m", dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
503 } |
2121 | 504 |
505 t_pop(); | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
506 return ret < 0 ? -1 : 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
507 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
508 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
509 static int maildir_sync_quick_check(struct maildir_sync_context *ctx, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 int *new_changed_r, int *cur_changed_r) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
511 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
512 struct index_mailbox *ibox = ctx->ibox; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
513 struct stat st; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
514 time_t new_mtime, cur_mtime; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
515 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
516 *new_changed_r = *cur_changed_r = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
517 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
518 if (stat(ctx->new_dir, &st) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
519 mail_storage_set_critical(ibox->box.storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
520 "stat(%s) failed: %m", ctx->new_dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
521 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
522 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
523 new_mtime = st.st_mtime; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
524 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
525 if (stat(ctx->cur_dir, &st) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
526 mail_storage_set_critical(ibox->box.storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
527 "stat(%s) failed: %m", ctx->cur_dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
528 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
529 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
530 cur_mtime = st.st_mtime; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
531 |
2064
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
532 if (ibox->dirty_cur_time == 0) { |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
533 /* cur stamp is kept in index, we don't have to sync if |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
534 someone else has done it and updated the index. make sure |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
535 we have a fresh index with latest sync_stamp. */ |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
536 struct mail_index_view *view; |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
537 const struct mail_index_header *hdr; |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
538 |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
539 if (mail_index_refresh(ibox->index) < 0) { |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
540 mail_storage_set_index_error(ibox); |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
541 return -1; |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
542 } |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
543 |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
544 view = mail_index_view_open(ibox->index); |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
545 if (mail_index_get_header(view, &hdr) < 0) { |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
546 mail_index_view_close(view); |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
547 mail_storage_set_index_error(ibox); |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
548 return -1; |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
549 } |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
550 ibox->last_cur_mtime = hdr->sync_stamp; |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
551 mail_index_view_close(view); |
1954 | 552 } |
553 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
554 if (new_mtime != ibox->last_new_mtime || |
1955 | 555 new_mtime >= ibox->last_new_sync_time - MAILDIR_SYNC_SECS) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
556 *new_changed_r = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
557 ibox->last_new_mtime = new_mtime; |
1955 | 558 ibox->last_new_sync_time = ioloop_time; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
559 } |
1954 | 560 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
561 if (cur_mtime != ibox->last_cur_mtime || |
1962 | 562 (ibox->dirty_cur_time != 0 && |
563 ioloop_time - ibox->dirty_cur_time > MAILDIR_SYNC_SECS)) { | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
564 /* cur/ changed, or delayed cur/ check */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
565 *cur_changed_r = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
566 ibox->last_cur_mtime = cur_mtime; |
1984 | 567 |
568 ibox->dirty_cur_time = | |
569 cur_mtime >= ioloop_time - MAILDIR_SYNC_SECS ? | |
570 cur_mtime : 0; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
571 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
572 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
573 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
574 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
575 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
576 static int maildir_sync_index(struct maildir_sync_context *ctx) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
577 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
578 struct index_mailbox *ibox = ctx->ibox; |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
579 struct maildir_index_sync_context sync_ctx; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
580 struct maildir_uidlist_iter_ctx *iter; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
581 struct mail_index_transaction *trans; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
582 struct mail_index_view *view; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
583 const struct mail_index_header *hdr; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
584 const struct mail_index_record *rec; |
1954 | 585 uint32_t seq, uid; |
586 enum maildir_uidlist_rec_flag uflags; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
587 const char *filename; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
588 enum mail_flags flags; |
1958 | 589 keywords_mask_t keywords; |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
590 uint32_t uid_validity, next_uid; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
591 int ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
592 |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
593 memset(&sync_ctx, 0, sizeof(sync_ctx)); |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
594 sync_ctx.ibox = ibox; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
595 |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
596 if (mail_index_sync_begin(ibox->index, &sync_ctx.sync_ctx, &view, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
597 (uint32_t)-1, (uoff_t)-1) <= 0) { |
1940 | 598 mail_storage_set_index_error(ibox); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
599 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
600 } |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
601 sync_ctx.view = view; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
602 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
603 ret = mail_index_get_header(view, &hdr); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
604 i_assert(ret == 0); /* view is locked, can't happen */ |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
605 |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
606 uid_validity = maildir_uidlist_get_uid_validity(ibox->uidlist); |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
607 if (uid_validity != hdr->uid_validity && |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
608 uid_validity != 0 && hdr->uid_validity != 0) { |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
609 /* uidvalidity changed and mailbox isn't being initialized, |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
610 index must be rebuilt */ |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
611 mail_storage_set_critical(ibox->box.storage, |
2067
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
612 "Maildir %s sync: UIDVALIDITY changed (%u -> %u)", |
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
613 ibox->path, hdr->uid_validity, uid_validity); |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
614 mail_index_mark_corrupted(ibox->index); |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
615 (void)mail_index_sync_end(sync_ctx.sync_ctx); |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
616 return -1; |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
617 } |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
618 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
619 trans = mail_index_transaction_begin(view, FALSE); |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
620 sync_ctx.trans = trans; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
621 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
622 seq = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
623 iter = maildir_uidlist_iter_init(ibox->uidlist); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
624 while (maildir_uidlist_iter_next(iter, &uid, &uflags, &filename)) { |
1958 | 625 maildir_filename_get_flags(filename, &flags, keywords); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
626 |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
627 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RECENT) != 0 && |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
628 (uflags & MAILDIR_UIDLIST_REC_FLAG_NEW_DIR) != 0 && |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
629 (uflags & MAILDIR_UIDLIST_REC_FLAG_MOVED) == 0) { |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
630 /* mail is recent for next session as well */ |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
631 flags |= MAIL_RECENT; |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
632 } |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
633 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
634 __again: |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
635 seq++; |
1954 | 636 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
637 if (seq > hdr->messages_count) { |
1984 | 638 if (uid < hdr->next_uid) { |
2053 | 639 /* most likely a race condition: we read the |
640 maildir, then someone else expunged messages | |
641 and committed changes to index. so, this | |
642 message shouldn't actually exist. mark it | |
643 racy and check in next sync. | |
644 | |
645 the difference between this and the later | |
646 check is that this one happens when messages | |
647 are expunged from the end */ | |
648 if ((uflags & | |
2228 | 649 MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { |
650 /* partial syncing */ | |
651 continue; | |
652 } | |
653 if ((uflags & | |
2053 | 654 MAILDIR_UIDLIST_REC_FLAG_RACING) != 0) { |
655 mail_storage_set_critical( | |
656 ibox->box.storage, | |
2067
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
657 "Maildir %s sync: " |
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
658 "UID < next_uid " |
2053 | 659 "(%u < %u, file = %s)", |
2067
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
660 ibox->path, uid, hdr->next_uid, |
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
661 filename); |
2053 | 662 mail_index_mark_corrupted(ibox->index); |
663 ret = -1; | |
664 break; | |
665 } | |
666 ibox->dirty_cur_time = ioloop_time; | |
667 maildir_uidlist_add_flags(ibox->uidlist, | |
668 filename, | |
669 MAILDIR_UIDLIST_REC_FLAG_RACING); | |
670 | |
671 seq--; | |
672 continue; | |
1984 | 673 } |
674 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
675 mail_index_append(trans, uid, &seq); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
676 mail_index_update_flags(trans, seq, MODIFY_REPLACE, |
1958 | 677 flags, keywords); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
678 continue; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
679 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
680 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
681 if (mail_index_lookup(view, seq, &rec) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
682 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
683 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
684 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
685 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
686 if (rec->uid < uid) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
687 /* expunged */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
688 mail_index_expunge(trans, seq); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
689 goto __again; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
690 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
691 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
692 if (rec->uid > uid) { |
2034
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
693 /* most likely a race condition: we read the |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
694 maildir, then someone else expunged messages and |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
695 committed changes to index. so, this message |
2053 | 696 shouldn't actually exist. mark it racy and check |
697 in next sync. */ | |
2228 | 698 if ((uflags & |
699 MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { | |
700 /* partial syncing */ | |
701 seq--; | |
702 continue; | |
703 } | |
2053 | 704 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RACING) != 0) { |
2034
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
705 mail_storage_set_critical(ibox->box.storage, |
2067
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
706 "Maildir %s sync: UID inserted in the " |
2034
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
707 "middle of mailbox " |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
708 "(%u > %u, file = %s)", |
2067
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
709 ibox->path, rec->uid, uid, filename); |
2034
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
710 mail_index_mark_corrupted(ibox->index); |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
711 ret = -1; |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
712 break; |
2064
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
713 } |
2053 | 714 |
715 ibox->dirty_cur_time = ioloop_time; | |
716 maildir_uidlist_add_flags(ibox->uidlist, filename, | |
717 MAILDIR_UIDLIST_REC_FLAG_RACING); | |
2034
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
718 |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
719 seq--; |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
720 continue; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
721 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
722 |
2320
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
723 if ((rec->flags & MAIL_RECENT) != 0) { |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
724 index_mailbox_set_recent(ibox, seq); |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
725 if (ibox->keep_recent) { |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
726 flags |= MAIL_RECENT; |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
727 } else { |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
728 mail_index_update_flags(trans, seq, |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
729 MODIFY_REMOVE, |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
730 MAIL_RECENT, keywords); |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
731 } |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
732 } |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
733 |
2228 | 734 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { |
735 /* partial syncing */ | |
736 continue; | |
737 } | |
738 | |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
739 if ((rec->flags & MAIL_INDEX_MAIL_FLAG_DIRTY) != 0) { |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
740 /* we haven't been able to update maildir with this |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
741 record's flag changes. don't sync them. */ |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
742 continue; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
743 } |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
744 |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
745 if (((uint8_t)flags & ~MAIL_RECENT) != |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
746 (rec->flags & (MAIL_FLAGS_MASK^MAIL_RECENT)) || |
1958 | 747 memcmp(keywords, rec->keywords, |
748 INDEX_KEYWORDS_BYTE_COUNT) != 0) { | |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
749 /* FIXME: this is wrong if there's pending changes in |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
750 transaction log already. it gets fixed in next sync |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
751 however.. */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
752 mail_index_update_flags(trans, seq, MODIFY_REPLACE, |
1958 | 753 flags, keywords); |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
754 } else if ((flags & MAIL_RECENT) == 0 && |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
755 (rec->flags & MAIL_RECENT) != 0) { |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
756 /* just remove recent flag */ |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
757 memset(keywords, 0, sizeof(keywords)); |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
758 mail_index_update_flags(trans, seq, MODIFY_REMOVE, |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
759 MAIL_RECENT, keywords); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
760 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
761 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
762 maildir_uidlist_iter_deinit(iter); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
763 |
1954 | 764 if (!ctx->partial) { |
765 /* expunge the rest */ | |
766 for (seq++; seq <= hdr->messages_count; seq++) | |
767 mail_index_expunge(trans, seq); | |
768 } | |
769 | |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
770 /* now, sync the index */ |
2239 | 771 ibox->syncing_commit = TRUE; |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
772 while ((ret = mail_index_sync_next(sync_ctx.sync_ctx, |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
773 &sync_ctx.sync_rec)) > 0) { |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
774 if (maildir_sync_record(ibox, &sync_ctx) < 0) { |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
775 ret = -1; |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
776 break; |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
777 } |
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
778 } |
2239 | 779 ibox->syncing_commit = FALSE; |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
780 |
2064
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
781 if (ibox->dirty_cur_time == 0 && |
5cfdc99fab69
Don't use internal last_cur_mtime stamp - it's index-specific so always get
Timo Sirainen <tss@iki.fi>
parents:
2053
diff
changeset
|
782 ibox->last_cur_mtime != (time_t)hdr->sync_stamp) { |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
783 uint32_t sync_stamp = ibox->last_cur_mtime; |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
784 |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
785 mail_index_update_header(trans, |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
786 offsetof(struct mail_index_header, sync_stamp), |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
787 &sync_stamp, sizeof(sync_stamp)); |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
788 } |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
789 |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
790 if (hdr->uid_validity == 0) { |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
791 /* get the initial uidvalidity */ |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
792 if (maildir_uidlist_update(ibox->uidlist) < 0) |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
793 ret = -1; |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
794 uid_validity = maildir_uidlist_get_uid_validity(ibox->uidlist); |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
795 if (uid_validity == 0) { |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
796 uid_validity = ioloop_time; |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
797 maildir_uidlist_set_uid_validity(ibox->uidlist, |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
798 uid_validity); |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
799 } |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
800 } else if (uid_validity == 0) { |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
801 maildir_uidlist_set_uid_validity(ibox->uidlist, |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
802 hdr->uid_validity); |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
803 } |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
804 |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
805 if (uid_validity != hdr->uid_validity && uid_validity != 0) { |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
806 mail_index_update_header(trans, |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
807 offsetof(struct mail_index_header, uid_validity), |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
808 &uid_validity, sizeof(uid_validity)); |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
809 } |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
810 |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
811 next_uid = maildir_uidlist_get_next_uid(ibox->uidlist); |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
812 if (next_uid != 0 && hdr->next_uid != next_uid) { |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
813 mail_index_update_header(trans, |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
814 offsetof(struct mail_index_header, next_uid), |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
815 &next_uid, sizeof(next_uid)); |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
816 } |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
817 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
818 if (ret < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
819 mail_index_transaction_rollback(trans); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
820 else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
821 uint32_t seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
822 uoff_t offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
823 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
824 if (mail_index_transaction_commit(trans, &seq, &offset) < 0) |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
825 ret = -1; |
2009
2e77ee652e2e
When committing with no changes, don't try to sync them later.
Timo Sirainen <tss@iki.fi>
parents:
1988
diff
changeset
|
826 else if (seq != 0) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
827 ibox->commit_log_file_seq = seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
828 ibox->commit_log_file_offset = offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
829 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
830 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
831 |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
832 if (mail_index_sync_end(sync_ctx.sync_ctx) < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
833 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
834 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
835 if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
836 ibox->commit_log_file_seq = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
837 ibox->commit_log_file_offset = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
838 } else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
839 mail_storage_set_index_error(ibox); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
840 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
841 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
842 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
843 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
844 |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
845 static int maildir_sync_context(struct maildir_sync_context *ctx, int forced) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
846 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
847 int ret, new_changed, cur_changed; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
848 |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
849 if (!forced) { |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
850 if (maildir_sync_quick_check(ctx, &new_changed, &cur_changed) < 0) |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
851 return -1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
852 |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
853 if (!new_changed && !cur_changed) |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
854 return 0; |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
855 } else { |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
856 new_changed = cur_changed = TRUE; |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
857 } |
1947 | 858 |
2121 | 859 /* we have to lock uidlist immediately, otherwise there's race |
860 conditions with other processes who might write older maildir | |
861 file list into uidlist. | |
862 | |
863 alternative would be to lock it when new files are found, but | |
2173
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
864 the directory scans _must_ be restarted then. |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
865 |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
866 if we got here through maildir_sync_last_commit(), we can't sync |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
867 index as it's already being synced. so, don't try locking uidlist |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
868 either, we only want to find new filename for some mail. |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
869 */ |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
870 if (!ctx->ibox->syncing_commit) { |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
871 if ((ret = maildir_uidlist_try_lock(ctx->ibox->uidlist)) < 0) |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
872 return ret; |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
873 if (ret == 0 && !forced) { |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
874 /* we didn't get a lock, don't do syncing unless we |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
875 really want to check for expunges or renames. new |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
876 files won't be added. */ |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
877 return 0; |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
878 } |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
879 } |
2123 | 880 |
881 ctx->partial = !cur_changed; | |
882 ctx->uidlist_sync_ctx = | |
883 maildir_uidlist_sync_init(ctx->ibox->uidlist, ctx->partial); | |
2121 | 884 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
885 if (maildir_scan_dir(ctx, TRUE) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
886 return -1; |
1954 | 887 if (cur_changed) { |
888 if (maildir_scan_dir(ctx, FALSE) < 0) | |
889 return -1; | |
890 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
891 |
1984 | 892 /* finish uidlist syncing, but keep it still locked */ |
2123 | 893 maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx); |
2173
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
894 if (!ctx->ibox->syncing_commit) { |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
895 if (maildir_sync_index(ctx) < 0) |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
896 return -1; |
9438951e243f
Don't crash if we're syncing last commit to maildir, but some file was lost
Timo Sirainen <tss@iki.fi>
parents:
2140
diff
changeset
|
897 } |
1984 | 898 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
899 ret = maildir_uidlist_sync_deinit(ctx->uidlist_sync_ctx); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
900 ctx->uidlist_sync_ctx = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
901 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
902 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
903 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
904 |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
905 int maildir_storage_sync_force(struct index_mailbox *ibox) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
906 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
907 struct maildir_sync_context *ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
908 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
909 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
910 ctx = maildir_sync_context_new(ibox); |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
911 ret = maildir_sync_context(ctx, TRUE); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
912 maildir_sync_deinit(ctx); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
913 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
914 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
915 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
916 struct mailbox_sync_context * |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
917 maildir_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
918 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
919 struct index_mailbox *ibox = (struct index_mailbox *)box; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
920 struct maildir_sync_context *ctx; |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
921 int ret = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
922 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
923 if ((flags & MAILBOX_SYNC_FLAG_FAST) == 0 || |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
924 ibox->sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <= ioloop_time) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
925 ibox->sync_last_check = ioloop_time; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
926 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
927 ctx = maildir_sync_context_new(ibox); |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
928 ret = maildir_sync_context(ctx, FALSE); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
929 maildir_sync_deinit(ctx); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
930 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
931 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
932 return index_mailbox_sync_init(box, flags, ret < 0); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
933 } |