Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/maildir/maildir-sync.c @ 4848:967de900c73a HEAD
Mailbox list indexing and related changes. Currently works only with
maildir and mmap_disable=no. This allows doing STATUS to synced mailboxes
without opening their index files at all.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 26 Nov 2006 00:17:39 +0200 |
parents | 615b7738a62f |
children | 24afafbfe47b |
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 | |
3520 | 8 check if changes have occurred is to stat() the new/ and cur/ |
1955 | 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 | |
3520 | 15 until a new modification occurred later. |
1955 | 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" |
3470
346a494c2feb
Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents:
3453
diff
changeset
|
175 #include "array.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 #include "buffer.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 #include "hash.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 #include "str.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 #include "maildir-storage.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
180 #include "maildir-uidlist.h" |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
181 #include "maildir-keywords.h" |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
182 #include "maildir-sync.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 #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
|
185 #include <stddef.h> |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 #include <unistd.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 #include <dirent.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 #include <sys/stat.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 #define MAILDIR_FILENAME_FLAG_FOUND 128 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 |
3435
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
192 /* When rename()ing many files from new/ to cur/, it's possible that next |
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
193 readdir() skips some files. we don't of course wish to lose them, so we |
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
194 go and rescan the new/ directory again from beginning until no files are |
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
195 left. This value is just an optimization to avoid checking the directory |
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
196 twice unneededly. usually only NFS is the problem case. 1 is the safest |
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
197 bet here, but I guess 5 will do just fine too. */ |
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
198 #define MAILDIR_RENAME_RESCAN_COUNT 5 |
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
199 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 struct maildir_sync_context { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
201 struct maildir_mailbox *mbox; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 const char *new_dir, *cur_dir; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
203 bool partial; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
205 struct maildir_uidlist_sync_ctx *uidlist_sync_ctx; |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
206 struct maildir_index_sync_context *index_sync_ctx; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
209 struct maildir_index_sync_context { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
210 struct maildir_mailbox *mbox; |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
211 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
|
212 struct mail_index_sync_ctx *sync_ctx; |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
213 struct maildir_keywords_sync_ctx *keywords_sync_ctx; |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
214 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
|
215 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
216 ARRAY_DEFINE(sync_recs, struct mail_index_sync_rec); |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
217 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
|
218 int dirty_state; |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
219 }; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
220 |
3775
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
221 struct maildir_keywords_sync_ctx * |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
222 maildir_sync_get_keywords_sync_ctx(struct maildir_index_sync_context *ctx) |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
223 { |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
224 return ctx->keywords_sync_ctx; |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
225 } |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
226 |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
227 int maildir_filename_get_flags(struct maildir_keywords_sync_ctx *ctx, |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
228 const char *fname, enum mail_flags *flags_r, |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
229 ARRAY_TYPE(keyword_indexes) *keywords_r) |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
230 { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
231 const char *info; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
232 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
233 array_clear(keywords_r); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
234 *flags_r = 0; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
235 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
236 info = strchr(fname, MAILDIR_INFO_SEP); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
237 if (info == NULL || info[1] != '2' || info[2] != MAILDIR_FLAGS_SEP) |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
238 return 0; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
239 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
240 for (info += 3; *info != '\0' && *info != MAILDIR_FLAGS_SEP; info++) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
241 switch (*info) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
242 case 'R': /* replied */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
243 *flags_r |= MAIL_ANSWERED; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
244 break; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
245 case 'S': /* seen */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
246 *flags_r |= MAIL_SEEN; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
247 break; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
248 case 'T': /* trashed */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
249 *flags_r |= MAIL_DELETED; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
250 break; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
251 case 'D': /* draft */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
252 *flags_r |= MAIL_DRAFT; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
253 break; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
254 case 'F': /* flagged */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
255 *flags_r |= MAIL_FLAGGED; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
256 break; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
257 default: |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
258 if (*info >= MAILDIR_KEYWORD_FIRST && |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
259 *info <= MAILDIR_KEYWORD_LAST) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
260 int idx; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
261 |
3775
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
262 idx = maildir_keywords_char_idx(ctx, *info); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
263 if (idx < 0) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
264 /* unknown keyword. */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
265 break; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
266 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
267 |
3563 | 268 array_append(keywords_r, |
269 (unsigned int *)&idx, 1); | |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
270 break; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
271 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
272 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
273 /* unknown flag - ignore */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
274 break; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
275 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
276 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
277 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
278 return 1; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
279 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
280 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
281 static void |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
282 maildir_filename_append_keywords(struct maildir_keywords_sync_ctx *ctx, |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
283 ARRAY_TYPE(keyword_indexes) *keywords, |
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
284 string_t *str) |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
285 { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
286 const unsigned int *indexes; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
287 unsigned int i, count; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
288 char chr; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
289 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
290 indexes = array_get(keywords, &count); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
291 for (i = 0; i < count; i++) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
292 chr = maildir_keywords_idx_char(ctx, indexes[i]); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
293 if (chr != '\0') |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
294 str_append_c(str, chr); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
295 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
296 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
297 |
3775
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
298 const char *maildir_filename_set_flags(struct maildir_keywords_sync_ctx *ctx, |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
299 const char *fname, enum mail_flags flags, |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
300 ARRAY_TYPE(keyword_indexes) *keywords) |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
301 { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
302 string_t *flags_str; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
303 enum mail_flags flags_left; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
304 const char *info, *oldflags; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
305 int nextflag; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
306 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
307 /* remove the old :info from file name, and get the old flags */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
308 info = strrchr(fname, MAILDIR_INFO_SEP); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
309 if (info != NULL && strrchr(fname, '/') > info) |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
310 info = NULL; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
311 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
312 oldflags = ""; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
313 if (info != NULL) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
314 fname = t_strdup_until(fname, info); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
315 if (info[1] == '2' && info[2] == MAILDIR_FLAGS_SEP) |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
316 oldflags = info+3; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
317 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
318 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
319 /* insert the new flags between old flags. flags must be sorted by |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
320 their ASCII code. unknown flags are kept. */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
321 flags_str = t_str_new(256); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
322 str_append(flags_str, fname); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
323 str_append(flags_str, MAILDIR_FLAGS_FULL_SEP); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
324 flags_left = flags; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
325 for (;;) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
326 /* skip all known flags */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
327 while (*oldflags == 'D' || *oldflags == 'F' || |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
328 *oldflags == 'R' || *oldflags == 'S' || |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
329 *oldflags == 'T' || |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
330 (*oldflags >= MAILDIR_KEYWORD_FIRST && |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
331 *oldflags <= MAILDIR_KEYWORD_LAST)) |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
332 oldflags++; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
333 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
334 nextflag = *oldflags == '\0' || *oldflags == MAILDIR_FLAGS_SEP ? |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
335 256 : (unsigned char) *oldflags; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
336 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
337 if ((flags_left & MAIL_DRAFT) && nextflag > 'D') { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
338 str_append_c(flags_str, 'D'); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
339 flags_left &= ~MAIL_DRAFT; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
340 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
341 if ((flags_left & MAIL_FLAGGED) && nextflag > 'F') { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
342 str_append_c(flags_str, 'F'); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
343 flags_left &= ~MAIL_FLAGGED; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
344 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
345 if ((flags_left & MAIL_ANSWERED) && nextflag > 'R') { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
346 str_append_c(flags_str, 'R'); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
347 flags_left &= ~MAIL_ANSWERED; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
348 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
349 if ((flags_left & MAIL_SEEN) && nextflag > 'S') { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
350 str_append_c(flags_str, 'S'); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
351 flags_left &= ~MAIL_SEEN; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
352 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
353 if ((flags_left & MAIL_DELETED) && nextflag > 'T') { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
354 str_append_c(flags_str, 'T'); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
355 flags_left &= ~MAIL_DELETED; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
356 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
357 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
358 if (keywords != NULL && array_is_created(keywords) && |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
359 nextflag > MAILDIR_KEYWORD_FIRST) { |
3775
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
360 maildir_filename_append_keywords(ctx, keywords, |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
361 flags_str); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
362 keywords = NULL; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
363 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
364 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
365 if (*oldflags == '\0' || *oldflags == MAILDIR_FLAGS_SEP) |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
366 break; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
367 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
368 str_append_c(flags_str, *oldflags); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
369 oldflags++; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
370 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
371 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
372 if (*oldflags == MAILDIR_FLAGS_SEP) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
373 /* another flagset, we don't know about these, just keep them */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
374 while (*oldflags != '\0') |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
375 str_append_c(flags_str, *oldflags++); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
376 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
377 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
378 return str_c(flags_str); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
379 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
380 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
381 static int maildir_expunge(struct maildir_mailbox *mbox, const char *path, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 void *context __attr_unused__) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 { |
1955 | 384 if (unlink(path) == 0) { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
385 mbox->dirty_cur_time = ioloop_time; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
386 return 1; |
1955 | 387 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
388 if (errno == ENOENT) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
391 mail_storage_set_critical(STORAGE(mbox->storage), |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 "unlink(%s) failed: %m", path); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
393 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
394 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
395 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
396 static int maildir_sync_flags(struct maildir_mailbox *mbox, const char *path, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 void *context) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
398 { |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
399 struct maildir_index_sync_context *ctx = context; |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
400 const struct mail_index_sync_rec *recs; |
4450
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
401 const char *dir, *fname, *newfname, *newpath; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
402 enum mail_flags flags; |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
403 ARRAY_TYPE(keyword_indexes) keywords; |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
404 unsigned int i, count; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 uint8_t flags8; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
406 |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
407 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
|
408 |
4450
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
409 fname = strrchr(path, '/'); |
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
410 i_assert(fname != NULL); |
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
411 fname++; |
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
412 dir = t_strdup_until(path, fname); |
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
413 |
4596
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
414 t_array_init(&keywords, 16); |
3775
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
415 (void)maildir_filename_get_flags(ctx->keywords_sync_ctx, |
4450
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
416 fname, &flags, &keywords); |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
417 flags8 = flags; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
418 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
419 recs = array_get_modifiable(&ctx->sync_recs, &count); |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
420 for (i = 0; i < count; i++) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
421 if (recs[i].uid1 != ctx->seq) |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
422 break; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
423 |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
424 switch (recs[i].type) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
425 case MAIL_INDEX_SYNC_TYPE_FLAGS: |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
426 mail_index_sync_flags_apply(&recs[i], &flags8); |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
427 break; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
428 case MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD: |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
429 case MAIL_INDEX_SYNC_TYPE_KEYWORD_REMOVE: |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
430 case MAIL_INDEX_SYNC_TYPE_KEYWORD_RESET: |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
431 mail_index_sync_keywords_apply(&recs[i], &keywords); |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
432 break; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
433 case MAIL_INDEX_SYNC_TYPE_APPEND: |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
434 case MAIL_INDEX_SYNC_TYPE_EXPUNGE: |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
435 i_unreached(); |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
436 break; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
437 } |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
438 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 |
4450
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
440 |
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
441 newfname = maildir_filename_set_flags(ctx->keywords_sync_ctx, |
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
442 fname, flags8, &keywords); |
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
443 newpath = t_strconcat(dir, newfname, NULL); |
1955 | 444 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
|
445 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
|
446 ctx->dirty_state = -1; |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
447 mbox->dirty_cur_time = ioloop_time; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 return 1; |
1955 | 449 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
450 if (errno == ENOENT) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
453 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
|
454 mail_index_update_flags(ctx->trans, ctx->seq, MODIFY_ADD, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2936
diff
changeset
|
455 MAIL_INDEX_MAIL_FLAG_DIRTY); |
2272
ced88553af0b
mail_index_sync_sort_flags() now merges flag changes so mail storage
Timo Sirainen <tss@iki.fi>
parents:
2258
diff
changeset
|
456 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
|
457 return 1; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
458 } |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
459 |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
460 mail_storage_set_critical(STORAGE(mbox->storage), |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
461 "rename(%s, %s) failed: %m", path, newpath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
465 static int |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
466 maildir_sync_record_commit_until(struct maildir_index_sync_context *ctx, |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
467 uint32_t last_seq) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 { |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
469 struct mail_index_sync_rec *recs; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
470 unsigned int i, count; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
471 uint32_t seq, uid; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
472 bool expunged, flag_changed; |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
473 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
474 recs = array_get_modifiable(&ctx->sync_recs, &count); |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
475 for (seq = recs[0].uid1; seq <= last_seq; seq++) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
476 expunged = flag_changed = FALSE; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
477 for (i = 0; i < count; i++) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
478 if (recs[i].uid1 > seq) |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
479 break; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
480 |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
481 i_assert(recs[i].uid1 == seq); |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
482 switch (recs[i].type) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
483 case MAIL_INDEX_SYNC_TYPE_EXPUNGE: |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
484 expunged = TRUE; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
485 break; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
486 case MAIL_INDEX_SYNC_TYPE_FLAGS: |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
487 case MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD: |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
488 case MAIL_INDEX_SYNC_TYPE_KEYWORD_REMOVE: |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
489 case MAIL_INDEX_SYNC_TYPE_KEYWORD_RESET: |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
490 flag_changed = TRUE; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
491 break; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
492 case MAIL_INDEX_SYNC_TYPE_APPEND: |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
493 i_unreached(); |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
494 break; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
495 } |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
496 } |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
497 |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
498 if (mail_index_lookup_uid(ctx->view, seq, &uid) < 0) |
2033
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
499 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
|
500 |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
501 ctx->seq = seq; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
502 if (expunged) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
503 if (maildir_file_do(ctx->mbox, uid, |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
504 maildir_expunge, ctx) < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
505 return -1; |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
506 } else if (flag_changed) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
507 if (maildir_file_do(ctx->mbox, uid, |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
508 maildir_sync_flags, ctx) < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
509 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 } |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
511 |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
512 for (i = count; i > 0; i--) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
513 if (++recs[i-1].uid1 > recs[i-1].uid2) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
514 array_delete(&ctx->sync_recs, i-1, 1); |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
515 recs = array_get_modifiable(&ctx->sync_recs, |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
516 &count); |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
517 if (count == 0) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
518 /* all sync_recs committed */ |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
519 return 0; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
520 } |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
521 } |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
522 } |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
523 } |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
524 return 0; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
525 } |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
526 |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
527 static int maildir_sync_record(struct maildir_index_sync_context *ctx, |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
528 const struct mail_index_sync_rec *sync_rec) |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
529 { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
530 struct mail_index_view *view = ctx->view; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
531 struct mail_index_sync_rec sync_copy; |
2033
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
532 |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
533 if (sync_rec == NULL) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
534 /* deinit */ |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
535 while (array_count(&ctx->sync_recs) > 0) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
536 if (maildir_sync_record_commit_until(ctx, |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
537 (uint32_t)-1) < 0) |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
538 return -1; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
539 } |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
540 return 0; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
541 } |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
542 |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
543 if (sync_rec->type == MAIL_INDEX_SYNC_TYPE_APPEND) |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
544 return 0; /* ignore */ |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
545 |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
546 /* convert to sequences to avoid looping through huge holes in |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
547 UID range */ |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
548 sync_copy = *sync_rec; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
549 if (mail_index_lookup_uid_range(view, sync_rec->uid1, |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
550 sync_rec->uid2, |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
551 &sync_copy.uid1, |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
552 &sync_copy.uid2) < 0) |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
553 return -1; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
554 |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
555 if (sync_copy.uid1 == 0) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
556 /* UIDs were expunged */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
557 return 0; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
558 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
559 |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
560 while (array_count(&ctx->sync_recs) > 0) { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
561 const struct mail_index_sync_rec *rec = |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
562 array_idx(&ctx->sync_recs, 0); |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
563 |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
564 i_assert(rec->uid1 <= sync_copy.uid1); |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
565 if (rec->uid1 == sync_copy.uid1) |
2033
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
566 break; |
4f6b1118a53d
Transaction log contains only UIDs now, no more sequences which just mess up
Timo Sirainen <tss@iki.fi>
parents:
2009
diff
changeset
|
567 |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
568 if (maildir_sync_record_commit_until(ctx, sync_copy.uid1-1) < 0) |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
569 return -1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
570 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
571 |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
572 array_append(&ctx->sync_recs, &sync_copy, 1); |
1915
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 |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
576 static int maildir_sync_index_records(struct maildir_index_sync_context *ctx) |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
577 { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
578 struct mail_index_sync_rec sync_rec; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
579 int ret; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
580 |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
581 ret = mail_index_sync_next(ctx->sync_ctx, &sync_rec); |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
582 if (ret <= 0) |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
583 return ret; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
584 |
4596
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
585 t_array_init(&ctx->sync_recs, 32); |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
586 do { |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
587 if (maildir_sync_record(ctx, &sync_rec) < 0) |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
588 return -1; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
589 |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
590 ret = mail_index_sync_next(ctx->sync_ctx, &sync_rec); |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
591 } while (ret > 0); |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
592 |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
593 if (maildir_sync_record(ctx, NULL) < 0) |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
594 return -1; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
595 return ret; |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
596 } |
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
597 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
598 static struct maildir_sync_context * |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
599 maildir_sync_context_new(struct maildir_mailbox *mbox) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
600 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
601 struct maildir_sync_context *ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
602 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
603 ctx = t_new(struct maildir_sync_context, 1); |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
604 ctx->mbox = mbox; |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
605 ctx->new_dir = t_strconcat(mbox->path, "/new", NULL); |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
606 ctx->cur_dir = t_strconcat(mbox->path, "/cur", NULL); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
607 return ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
608 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
609 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
610 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
|
611 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
612 if (ctx->uidlist_sync_ctx != NULL) |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
613 (void)maildir_uidlist_sync_deinit(&ctx->uidlist_sync_ctx); |
4774
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
614 if (ctx->index_sync_ctx != NULL) { |
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
615 (void)maildir_sync_index_finish(&ctx->index_sync_ctx, |
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
616 TRUE, FALSE); |
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
617 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
618 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
619 |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
620 static int maildir_fix_duplicate(struct maildir_sync_context *ctx, |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
621 const char *dir, const char *old_fname) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
622 { |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
623 struct maildir_mailbox *mbox = ctx->mbox; |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
624 const char *existing_fname, *existing_path; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
625 const char *new_fname, *old_path, *new_path; |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
626 struct stat st, st2; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
627 int ret = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
628 |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
629 existing_fname = |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
630 maildir_uidlist_sync_get_full_filename(ctx->uidlist_sync_ctx, |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
631 old_fname); |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
632 i_assert(existing_fname != NULL); |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
633 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
634 t_push(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
635 |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
636 existing_path = t_strconcat(dir, "/", existing_fname, NULL); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
637 old_path = t_strconcat(dir, "/", old_fname, NULL); |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
638 |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
639 if (stat(existing_path, &st) < 0 || |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
640 stat(old_path, &st2) < 0) { |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
641 /* most likely the files just don't exist anymore. |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
642 don't really care about other errors much. */ |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
643 t_pop(); |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
644 return 0; |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
645 } |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
646 if (st.st_ino == st2.st_ino && CMP_DEV_T(st.st_dev, st2.st_dev)) { |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
647 /* files are the same. this means either a race condition |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
648 between stat() calls, or someone has started link()ing the |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
649 files. either way there's no data loss if we just leave it |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
650 there. */ |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
651 t_pop(); |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
652 return 0; |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
653 } |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
654 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
655 new_fname = maildir_generate_tmp_filename(&ioloop_timeval); |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
656 new_path = t_strconcat(mbox->path, "/new/", new_fname, NULL); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
657 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
658 if (rename(old_path, new_path) == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
659 i_warning("Fixed duplicate in %s: %s -> %s", |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
660 mbox->path, old_fname, new_fname); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
661 } else if (errno != ENOENT) { |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
662 mail_storage_set_critical(STORAGE(mbox->storage), |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
663 "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
|
664 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
665 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
666 t_pop(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
667 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
668 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
669 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
670 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
671 static int maildir_scan_dir(struct maildir_sync_context *ctx, bool new_dir) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
672 { |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
673 struct mail_storage *storage = STORAGE(ctx->mbox->storage); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
674 const char *dir; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
675 DIR *dirp; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
676 string_t *src, *dest; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
677 struct dirent *dp; |
3435
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
678 enum maildir_uidlist_rec_flag flags; |
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
679 unsigned int moves = 0; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
680 int ret = 1; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
681 bool move_new; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
682 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
683 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
|
684 dirp = opendir(dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
685 if (dirp == NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
686 mail_storage_set_critical(storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
687 "opendir(%s) failed: %m", dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
688 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
689 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
690 |
2121 | 691 t_push(); |
692 src = t_str_new(1024); | |
693 dest = t_str_new(1024); | |
694 | |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
695 move_new = new_dir && !mailbox_is_readonly(&ctx->mbox->ibox.box) && |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
696 !ctx->mbox->ibox.keep_recent; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
697 while ((dp = readdir(dirp)) != NULL) { |
2258
087a43e29492
No maildir filename checking after all.
Timo Sirainen <tss@iki.fi>
parents:
2256
diff
changeset
|
698 if (dp->d_name[0] == '.') |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
699 continue; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
700 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
701 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
|
702 dp->d_name); |
1984 | 703 if (ret == 0) { |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
704 /* 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
|
705 later in next sync. */ |
1984 | 706 if (new_dir) |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
707 ctx->mbox->last_new_mtime = 0; |
1984 | 708 else |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
709 ctx->mbox->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
|
710 continue; |
1984 | 711 } |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
712 if (ret < 0) |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
713 break; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
714 |
1947 | 715 flags = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
716 if (move_new) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
717 str_truncate(src, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
718 str_truncate(dest, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
719 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
|
720 str_printfa(dest, "%s/%s", ctx->cur_dir, dp->d_name); |
3417
b0bdf32564b7
Replaced ':' and ',' character usages with #defines, so they can be changed
Timo Sirainen <tss@iki.fi>
parents:
3340
diff
changeset
|
721 if (strchr(dp->d_name, MAILDIR_INFO_SEP) == NULL) { |
b0bdf32564b7
Replaced ':' and ',' character usages with #defines, so they can be changed
Timo Sirainen <tss@iki.fi>
parents:
3340
diff
changeset
|
722 str_append(dest, MAILDIR_FLAGS_FULL_SEP); |
b0bdf32564b7
Replaced ':' and ',' character usages with #defines, so they can be changed
Timo Sirainen <tss@iki.fi>
parents:
3340
diff
changeset
|
723 } |
1947 | 724 if (rename(str_c(src), str_c(dest)) == 0) { |
1984 | 725 /* we moved it - it's \Recent for us */ |
3435
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
726 moves++; |
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
727 ctx->mbox->dirty_cur_time = ioloop_time; |
1947 | 728 flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED | |
729 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
730 } else if (ENOTFOUND(errno)) { | |
731 /* someone else moved it already */ | |
3435
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
732 moves++; |
1947 | 733 flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED; |
4199
fa135b615b01
If maildir is readonly, don't complain about rename() failing to move mails
Timo Sirainen <tss@iki.fi>
parents:
4152
diff
changeset
|
734 } else if (ENOSPACE(errno) || errno == EACCES) { |
fa135b615b01
If maildir is readonly, don't complain about rename() failing to move mails
Timo Sirainen <tss@iki.fi>
parents:
4152
diff
changeset
|
735 /* not enough disk space / read-only maildir, |
fa135b615b01
If maildir is readonly, don't complain about rename() failing to move mails
Timo Sirainen <tss@iki.fi>
parents:
4152
diff
changeset
|
736 leave here */ |
1947 | 737 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | |
738 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
739 move_new = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
740 } else { |
1947 | 741 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | |
742 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
743 mail_storage_set_critical(storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
744 "rename(%s, %s) failed: %m", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
745 str_c(src), str_c(dest)); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
746 } |
1947 | 747 } else if (new_dir) { |
748 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | | |
749 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
750 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
751 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
752 ret = maildir_uidlist_sync_next(ctx->uidlist_sync_ctx, |
1947 | 753 dp->d_name, flags); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
754 if (ret <= 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
755 if (ret < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
756 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
757 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
758 /* possibly duplicate - try fixing it */ |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
759 if (maildir_fix_duplicate(ctx, dir, dp->d_name) < 0) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
760 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
761 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
762 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
763 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
764 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
765 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
766 if (closedir(dirp) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
767 mail_storage_set_critical(storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
768 "closedir(%s) failed: %m", dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
769 } |
2121 | 770 |
771 t_pop(); | |
3435
6f7ce690358e
If we have rename()d more than 5 files from new/ to cur/, rescan the
Timo Sirainen <tss@iki.fi>
parents:
3417
diff
changeset
|
772 return ret < 0 ? -1 : (moves <= MAILDIR_RENAME_RESCAN_COUNT ? 0 : 1); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
773 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
774 |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
775 static void |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
776 maildir_sync_update_from_header(struct maildir_mailbox *mbox, |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
777 struct mail_index_header *hdr_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
778 { |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
779 struct mail_index_view *view; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
780 const struct mail_index_header *hdr; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
781 |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
782 /* open a new view so we get the latest header */ |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
783 view = mail_index_view_open(mbox->ibox.index); |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
784 hdr = mail_index_get_header(view); |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
785 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
786 /* FIXME: ugly, replace with extension header */ |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
787 mbox->last_new_mtime = hdr->sync_size & 0xffffffff; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
788 mbox->last_dirty_flags = (hdr->sync_size >> 32) & |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
789 (MAILDIR_DIRTY_NEW | MAILDIR_DIRTY_CUR); |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
790 |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
791 mbox->last_cur_mtime = hdr->sync_stamp; |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
792 |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
793 if ((mbox->last_dirty_flags & MAILDIR_DIRTY_CUR) != 0 && |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
794 mbox->dirty_cur_time < mbox->last_cur_mtime) |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
795 mbox->dirty_cur_time = mbox->last_cur_mtime; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
796 |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
797 *hdr_r = *hdr; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
798 mail_index_view_close(&view); |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
799 } |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
800 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
801 static int |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
802 maildir_sync_quick_check(struct maildir_mailbox *mbox, |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
803 const char *new_dir, const char *cur_dir, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
804 bool *new_changed_r, bool *cur_changed_r) |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
805 { |
4126
63d6890803b3
If mailbox is opened in non-readonly state and there are mails in new/, make
Timo Sirainen <tss@iki.fi>
parents:
4107
diff
changeset
|
806 struct index_mailbox *ibox = &mbox->ibox; |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
807 struct mail_index_header hdr; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
808 struct stat st; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
809 time_t new_mtime, cur_mtime; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
810 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
811 *new_changed_r = *cur_changed_r = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
812 |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
813 if (stat(new_dir, &st) < 0) { |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
814 mail_storage_set_critical(STORAGE(mbox->storage), |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
815 "stat(%s) failed: %m", new_dir); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
816 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
817 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
818 new_mtime = st.st_mtime; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
819 |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
820 if (stat(cur_dir, &st) < 0) { |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
821 mail_storage_set_critical(STORAGE(mbox->storage), |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
822 "stat(%s) failed: %m", cur_dir); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
823 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
824 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
825 cur_mtime = st.st_mtime; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
826 |
2893
fd431866c674
mail_index_refresh() isn't public anymore, mail_index_view_open_locked()
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
827 /* cur stamp is kept in index, we don't have to sync if |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
828 someone else has done it and updated the index. |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
829 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
830 FIXME: For now we're using sync_size field as the new/ dir's stamp. |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
831 Pretty ugly.. */ |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
832 maildir_sync_update_from_header(mbox, &hdr); |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
833 if ((mbox->dirty_cur_time == 0 && cur_mtime != mbox->last_cur_mtime) || |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
834 (new_mtime != mbox->last_new_mtime)) { |
2893
fd431866c674
mail_index_refresh() isn't public anymore, mail_index_view_open_locked()
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
835 /* check if the index has been updated.. */ |
4126
63d6890803b3
If mailbox is opened in non-readonly state and there are mails in new/, make
Timo Sirainen <tss@iki.fi>
parents:
4107
diff
changeset
|
836 if (mail_index_refresh(ibox->index) < 0) { |
63d6890803b3
If mailbox is opened in non-readonly state and there are mails in new/, make
Timo Sirainen <tss@iki.fi>
parents:
4107
diff
changeset
|
837 mail_storage_set_index_error(ibox); |
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
|
838 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
|
839 } |
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
|
840 |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
841 maildir_sync_update_from_header(mbox, &hdr); |
1954 | 842 } |
843 | |
4126
63d6890803b3
If mailbox is opened in non-readonly state and there are mails in new/, make
Timo Sirainen <tss@iki.fi>
parents:
4107
diff
changeset
|
844 /* If we're removing recent flags, always sync new/ directory if |
63d6890803b3
If mailbox is opened in non-readonly state and there are mails in new/, make
Timo Sirainen <tss@iki.fi>
parents:
4107
diff
changeset
|
845 it has mails. */ |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
846 if (new_mtime != mbox->last_new_mtime || |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
847 ((mbox->last_dirty_flags & MAILDIR_DIRTY_NEW) != 0 && |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
848 new_mtime < ioloop_time - MAILDIR_SYNC_SECS) || |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
849 (!ibox->keep_recent && hdr.recent_messages_count > 0)) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
850 *new_changed_r = TRUE; |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
851 mbox->last_new_mtime = new_mtime; |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
852 |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
853 if (new_mtime < ioloop_time - MAILDIR_SYNC_SECS) |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
854 mbox->last_dirty_flags &= ~MAILDIR_DIRTY_NEW; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
855 else |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
856 mbox->last_dirty_flags |= MAILDIR_DIRTY_NEW; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
857 } |
1954 | 858 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
859 if (cur_mtime != mbox->last_cur_mtime || |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
860 (mbox->dirty_cur_time != 0 && |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
861 ioloop_time - mbox->dirty_cur_time > MAILDIR_SYNC_SECS)) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
862 /* cur/ changed, or delayed cur/ check */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
863 *cur_changed_r = TRUE; |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
864 mbox->last_cur_mtime = cur_mtime; |
1984 | 865 |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
866 if (cur_mtime < ioloop_time - MAILDIR_SYNC_SECS) { |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
867 mbox->last_dirty_flags &= ~MAILDIR_DIRTY_CUR; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
868 mbox->dirty_cur_time = 0; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
869 } else { |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
870 mbox->last_dirty_flags |= MAILDIR_DIRTY_CUR; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
871 mbox->dirty_cur_time = cur_mtime; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
872 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
873 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
874 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
875 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
876 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
877 |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
878 int maildir_sync_index_begin(struct maildir_mailbox *mbox, |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
879 struct maildir_index_sync_context **ctx_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
880 { |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
881 struct maildir_index_sync_context *ctx; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
882 struct mail_index_sync_ctx *sync_ctx; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
883 struct mail_index_view *view; |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
884 |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
885 if (mail_index_sync_begin(mbox->ibox.index, &sync_ctx, &view, |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
886 (uint32_t)-1, (uoff_t)-1, |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
887 FALSE, FALSE) <= 0) { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
888 mail_storage_set_index_error(&mbox->ibox); |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
889 return -1; |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
890 } |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
891 |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
892 ctx = i_new(struct maildir_index_sync_context, 1); |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
893 ctx->mbox = mbox; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
894 ctx->sync_ctx = sync_ctx; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
895 ctx->view = view; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
896 ctx->keywords_sync_ctx = |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
897 maildir_keywords_sync_init(mbox->keywords, mbox->ibox.index); |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
898 *ctx_r = ctx; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
899 return 0; |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
900 } |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
901 |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
902 int maildir_sync_index_finish(struct maildir_index_sync_context **_sync_ctx, |
4774
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
903 bool failed, bool cancel) |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
904 { |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
905 struct maildir_index_sync_context *sync_ctx = *_sync_ctx; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
906 struct maildir_mailbox *mbox = sync_ctx->mbox; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
907 uint32_t seq; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
908 uoff_t offset; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
909 int ret = failed ? -1 : 0; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
910 |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
911 *_sync_ctx = NULL; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
912 |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
913 if (sync_ctx->trans != NULL) { |
4774
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
914 if (ret < 0 || cancel) |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
915 mail_index_transaction_rollback(&sync_ctx->trans); |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
916 else { |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
917 if (mail_index_transaction_commit(&sync_ctx->trans, |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
918 &seq, &offset) < 0) |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
919 ret = -1; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
920 else if (seq != 0) { |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
921 mbox->ibox.commit_log_file_seq = seq; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
922 mbox->ibox.commit_log_file_offset = offset; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
923 } |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
924 } |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
925 } |
4774
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
926 if (ret < 0 || cancel) |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
927 mail_index_sync_rollback(&sync_ctx->sync_ctx); |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
928 else { |
4612
2c033ffc8f6f
maildir_storage_sync_force() crashed if called from mail index sync/expunge
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
929 /* Set syncing_commit=TRUE so that if any sync callbacks try |
2c033ffc8f6f
maildir_storage_sync_force() crashed if called from mail index sync/expunge
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
930 to access mails which got lost (eg. expunge callback trying |
2c033ffc8f6f
maildir_storage_sync_force() crashed if called from mail index sync/expunge
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
931 to open the file which was just unlinked) we don't try to |
2c033ffc8f6f
maildir_storage_sync_force() crashed if called from mail index sync/expunge
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
932 start a second index sync and crash. */ |
2c033ffc8f6f
maildir_storage_sync_force() crashed if called from mail index sync/expunge
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
933 mbox->syncing_commit = TRUE; |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
934 if (mail_index_sync_commit(&sync_ctx->sync_ctx) < 0) |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
935 ret = -1; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
936 else { |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
937 mbox->ibox.commit_log_file_seq = 0; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
938 mbox->ibox.commit_log_file_offset = 0; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
939 } |
4612
2c033ffc8f6f
maildir_storage_sync_force() crashed if called from mail index sync/expunge
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
940 mbox->syncing_commit = FALSE; |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
941 } |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
942 |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
943 if (ret < 0) |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
944 mail_storage_set_index_error(&mbox->ibox); |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
945 |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
946 maildir_keywords_sync_deinit(sync_ctx->keywords_sync_ctx); |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
947 sync_ctx->keywords_sync_ctx = NULL; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
948 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
949 i_free(sync_ctx); |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
950 return ret; |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
951 } |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
952 |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
953 int maildir_sync_index(struct maildir_index_sync_context *sync_ctx, |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
954 bool partial) |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
955 { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
956 struct maildir_mailbox *mbox = sync_ctx->mbox; |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
957 struct mail_index_view *view = sync_ctx->view; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
958 struct maildir_uidlist_iter_ctx *iter; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
959 struct mail_index_transaction *trans; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
960 const struct mail_index_header *hdr; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
961 const struct mail_index_record *rec; |
1954 | 962 uint32_t seq, uid; |
963 enum maildir_uidlist_rec_flag uflags; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
964 const char *filename; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
965 enum mail_flags flags; |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
966 ARRAY_TYPE(keyword_indexes) keywords; |
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
967 ARRAY_TYPE(keyword_indexes) idx_keywords; |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
968 uint32_t uid_validity, next_uid; |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
969 uint64_t value; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
970 int ret = 0; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
971 bool full_rescan = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
972 |
3453 | 973 i_assert(maildir_uidlist_is_locked(sync_ctx->mbox->uidlist)); |
974 | |
2892
62d53b49110d
Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
975 hdr = mail_index_get_header(view); |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
976 uid_validity = maildir_uidlist_get_uid_validity(mbox->uidlist); |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
977 if (uid_validity != hdr->uid_validity && |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
978 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
|
979 /* uidvalidity changed and mailbox isn't being initialized, |
3322
49071cc19102
If UIDVALIDITY changes, don't invalidate the whole index. Just expunge all
Timo Sirainen <tss@iki.fi>
parents:
3280
diff
changeset
|
980 reset mailbox so we can add all messages as new */ |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
981 mail_storage_set_critical(STORAGE(mbox->storage), |
2067
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
982 "Maildir %s sync: UIDVALIDITY changed (%u -> %u)", |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
983 mbox->path, hdr->uid_validity, uid_validity); |
3322
49071cc19102
If UIDVALIDITY changes, don't invalidate the whole index. Just expunge all
Timo Sirainen <tss@iki.fi>
parents:
3280
diff
changeset
|
984 |
3340
9c8220dfde7c
Don't try to handle UIDVALIDITY changes nicely after all. It causes
Timo Sirainen <tss@iki.fi>
parents:
3322
diff
changeset
|
985 mail_index_mark_corrupted(mbox->ibox.index); |
9c8220dfde7c
Don't try to handle UIDVALIDITY changes nicely after all. It causes
Timo Sirainen <tss@iki.fi>
parents:
3322
diff
changeset
|
986 return -1; |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
987 } |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
988 |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
989 sync_ctx->trans = trans = |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
990 mail_index_transaction_begin(sync_ctx->view, FALSE, TRUE); |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
991 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
992 seq = 0; |
4596
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
993 t_array_init(&keywords, MAILDIR_MAX_KEYWORDS); |
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
994 t_array_init(&idx_keywords, MAILDIR_MAX_KEYWORDS); |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
995 iter = maildir_uidlist_iter_init(mbox->uidlist); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
996 while (maildir_uidlist_iter_next(iter, &uid, &uflags, &filename)) { |
3775
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
997 maildir_filename_get_flags(sync_ctx->keywords_sync_ctx, |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
998 filename, &flags, &keywords); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
999 |
4107
d29677c59dc5
Keep \Seen flags privately only in indexes with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1000 /* the private flags are kept only in indexes. don't use them |
d29677c59dc5
Keep \Seen flags privately only in indexes with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1001 at all even for newly seen mails */ |
d29677c59dc5
Keep \Seen flags privately only in indexes with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1002 flags &= ~mbox->private_flags_mask; |
d29677c59dc5
Keep \Seen flags privately only in indexes with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1003 |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
1004 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
|
1005 (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
|
1006 (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
|
1007 /* 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
|
1008 flags |= MAIL_RECENT; |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
1009 } |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
1010 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1011 __again: |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1012 seq++; |
1954 | 1013 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1014 if (seq > hdr->messages_count) { |
1984 | 1015 if (uid < hdr->next_uid) { |
2053 | 1016 /* most likely a race condition: we read the |
1017 maildir, then someone else expunged messages | |
1018 and committed changes to index. so, this | |
1019 message shouldn't actually exist. mark it | |
1020 racy and check in next sync. | |
1021 | |
1022 the difference between this and the later | |
1023 check is that this one happens when messages | |
1024 are expunged from the end */ | |
1025 if ((uflags & | |
2228 | 1026 MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { |
1027 /* partial syncing */ | |
1028 continue; | |
1029 } | |
1030 if ((uflags & | |
2053 | 1031 MAILDIR_UIDLIST_REC_FLAG_RACING) != 0) { |
1032 mail_storage_set_critical( | |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
1033 STORAGE(mbox->storage), |
2067
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
1034 "Maildir %s sync: " |
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
1035 "UID < next_uid " |
2053 | 1036 "(%u < %u, file = %s)", |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1037 mbox->path, uid, hdr->next_uid, |
2067
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
1038 filename); |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1039 mail_index_mark_corrupted( |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1040 mbox->ibox.index); |
2053 | 1041 ret = -1; |
1042 break; | |
1043 } | |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1044 mbox->dirty_cur_time = ioloop_time; |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1045 maildir_uidlist_add_flags(mbox->uidlist, |
2053 | 1046 filename, |
1047 MAILDIR_UIDLIST_REC_FLAG_RACING); | |
1048 | |
1049 seq--; | |
1050 continue; | |
1984 | 1051 } |
1052 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1053 mail_index_append(trans, uid, &seq); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1054 mail_index_update_flags(trans, seq, MODIFY_REPLACE, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2936
diff
changeset
|
1055 flags); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1056 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1057 if (array_count(&keywords) > 0) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1058 struct mail_keywords *kw; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1059 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1060 kw = mail_index_keywords_create_from_indexes( |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1061 trans, &keywords); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1062 mail_index_update_keywords(trans, seq, |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1063 MODIFY_REPLACE, kw); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1064 mail_index_keywords_free(&kw); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1065 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1066 continue; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1067 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1068 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1069 if (mail_index_lookup(view, seq, &rec) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1070 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1071 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1072 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1073 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1074 if (rec->uid < uid) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1075 /* expunged */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1076 mail_index_expunge(trans, seq); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1077 goto __again; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1078 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1079 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1080 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
|
1081 /* 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
|
1082 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
|
1083 committed changes to index. so, this message |
2053 | 1084 shouldn't actually exist. mark it racy and check |
1085 in next sync. */ | |
2228 | 1086 if ((uflags & |
1087 MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { | |
1088 /* partial syncing */ | |
1089 seq--; | |
1090 continue; | |
1091 } | |
2053 | 1092 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RACING) != 0) { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1093 mail_storage_set_critical( |
3280
2c72492dfd91
Created mbox_storage and maildir_storage.
Timo Sirainen <tss@iki.fi>
parents:
3279
diff
changeset
|
1094 STORAGE(mbox->storage), |
2570 | 1095 "Maildir %s sync: " |
1096 "UID inserted in the middle of mailbox " | |
2034
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
1097 "(%u > %u, file = %s)", |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1098 mbox->path, rec->uid, uid, filename); |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1099 mail_index_mark_corrupted(mbox->ibox.index); |
2034
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
1100 ret = -1; |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
1101 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
|
1102 } |
2053 | 1103 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1104 mbox->dirty_cur_time = ioloop_time; |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1105 maildir_uidlist_add_flags(mbox->uidlist, filename, |
2053 | 1106 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
|
1107 |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
1108 seq--; |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
1109 continue; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1110 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1111 |
4107
d29677c59dc5
Keep \Seen flags privately only in indexes with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1112 /* the private flags are stored only in indexes, keep them */ |
d29677c59dc5
Keep \Seen flags privately only in indexes with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1113 flags |= rec->flags & mbox->private_flags_mask; |
d29677c59dc5
Keep \Seen flags privately only in indexes with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
1114 |
2320
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
1115 if ((rec->flags & MAIL_RECENT) != 0) { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1116 index_mailbox_set_recent(&mbox->ibox, seq); |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1117 if (mbox->ibox.keep_recent) { |
2320
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
1118 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
|
1119 } else { |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
1120 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
|
1121 MODIFY_REMOVE, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2936
diff
changeset
|
1122 MAIL_RECENT); |
2320
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
1123 } |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
1124 } |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
1125 |
2228 | 1126 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { |
1127 /* partial syncing */ | |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1128 if ((flags & MAIL_RECENT) != 0) { |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1129 /* we last saw this mail in new/, but it's |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1130 not there anymore. possibly expunged, |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1131 make sure. */ |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1132 full_rescan = TRUE; |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1133 } |
2228 | 1134 continue; |
1135 } | |
1136 | |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
1137 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
|
1138 /* 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
|
1139 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
|
1140 continue; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
1141 } |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
1142 |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
1143 if (((uint8_t)flags & ~MAIL_RECENT) != |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2936
diff
changeset
|
1144 (rec->flags & (MAIL_FLAGS_MASK^MAIL_RECENT))) { |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
1145 /* 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
|
1146 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
|
1147 however.. */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1148 mail_index_update_flags(trans, seq, MODIFY_REPLACE, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2936
diff
changeset
|
1149 flags); |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
1150 } 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
|
1151 (rec->flags & MAIL_RECENT) != 0) { |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
1152 /* just remove recent flag */ |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
1153 mail_index_update_flags(trans, seq, MODIFY_REMOVE, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2936
diff
changeset
|
1154 MAIL_RECENT); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1155 } |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1156 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1157 /* update keywords if they have changed */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1158 if (mail_index_lookup_keywords(view, seq, &idx_keywords) < 0) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1159 ret = -1; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1160 break; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1161 } |
3821
c8b2ed2c9961
We assumed that keyword index arrays were always sorted. This isn't always
Timo Sirainen <tss@iki.fi>
parents:
3776
diff
changeset
|
1162 if (!index_keyword_array_cmp(&keywords, &idx_keywords)) { |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1163 struct mail_keywords *kw; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1164 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1165 kw = mail_index_keywords_create_from_indexes( |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1166 trans, &keywords); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1167 mail_index_update_keywords(trans, seq, |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1168 MODIFY_REPLACE, kw); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1169 mail_index_keywords_free(&kw); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1170 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1171 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1172 maildir_uidlist_iter_deinit(iter); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1173 array_free(&keywords); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1174 |
3776
0cae3268c8af
Accidentally had changed !partial-check to partial-check. Because of this
Timo Sirainen <tss@iki.fi>
parents:
3775
diff
changeset
|
1175 if (!partial) { |
1954 | 1176 /* expunge the rest */ |
1177 for (seq++; seq <= hdr->messages_count; seq++) | |
1178 mail_index_expunge(trans, seq); | |
3583
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1179 |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1180 /* next_uid must be updated only in non-partial syncs since |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1181 partial syncs don't add the new mails to index. also we'll |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1182 have to do it here before syncing index records, since after |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1183 that the uidlist's next_uid value may have changed. */ |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1184 next_uid = maildir_uidlist_get_next_uid(mbox->uidlist); |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1185 if (next_uid != 0 && hdr->next_uid != next_uid) { |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1186 mail_index_update_header(trans, |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1187 offsetof(struct mail_index_header, next_uid), |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1188 &next_uid, sizeof(next_uid), FALSE); |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1189 } |
1954 | 1190 } |
1191 | |
3583
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1192 if (!mbox->syncing_commit) { |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1193 /* now, sync the index. NOTE: may recurse back to here with |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1194 partial syncs */ |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1195 mbox->syncing_commit = TRUE; |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1196 if (maildir_sync_index_records(sync_ctx) < 0) |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1197 ret = -1; |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1198 mbox->syncing_commit = FALSE; |
a45208fe7c83
Partial syncs caused index's next_uid to be updated even if the new mails
Timo Sirainen <tss@iki.fi>
parents:
3579
diff
changeset
|
1199 } |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
1200 |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1201 if (mbox->dirty_cur_time != 0) |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1202 mbox->last_dirty_flags |= MAILDIR_DIRTY_CUR; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1203 |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1204 if (mbox->last_cur_mtime != (time_t)hdr->sync_stamp) { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1205 uint32_t sync_stamp = mbox->last_cur_mtime; |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
1206 |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
1207 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
|
1208 offsetof(struct mail_index_header, sync_stamp), |
3322
49071cc19102
If UIDVALIDITY changes, don't invalidate the whole index. Just expunge all
Timo Sirainen <tss@iki.fi>
parents:
3280
diff
changeset
|
1209 &sync_stamp, sizeof(sync_stamp), TRUE); |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
1210 } |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
1211 |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1212 /* FIXME: use a header extension instead of sync_size.. */ |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1213 value = mbox->last_new_mtime | |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1214 ((uint64_t)mbox->last_dirty_flags << 32); |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1215 if (value != hdr->sync_size) { |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1216 mail_index_update_header(trans, |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1217 offsetof(struct mail_index_header, sync_size), |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1218 &value, sizeof(value), TRUE); |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1219 } |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1220 |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1221 if (hdr->uid_validity == 0) { |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1222 /* get the initial uidvalidity */ |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1223 if (maildir_uidlist_update(mbox->uidlist) < 0) |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1224 ret = -1; |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1225 uid_validity = maildir_uidlist_get_uid_validity(mbox->uidlist); |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1226 if (uid_validity == 0) { |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1227 uid_validity = ioloop_time; |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1228 maildir_uidlist_set_uid_validity(mbox->uidlist, |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1229 uid_validity); |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1230 } |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1231 } else if (uid_validity == 0) { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1232 maildir_uidlist_set_uid_validity(mbox->uidlist, |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1233 hdr->uid_validity); |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1234 } |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1235 |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1236 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
|
1237 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
|
1238 offsetof(struct mail_index_header, uid_validity), |
3322
49071cc19102
If UIDVALIDITY changes, don't invalidate the whole index. Just expunge all
Timo Sirainen <tss@iki.fi>
parents:
3280
diff
changeset
|
1239 &uid_validity, sizeof(uid_validity), TRUE); |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
1240 } |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
1241 |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1242 return ret < 0 ? -1 : (full_rescan ? 0 : 1); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1243 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1244 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
1245 static int maildir_sync_context(struct maildir_sync_context *ctx, bool forced, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
1246 bool sync_last_commit) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1247 { |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
1248 bool new_changed, cur_changed, full_rescan = FALSE; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
1249 int ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1250 |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1251 if (sync_last_commit) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1252 new_changed = cur_changed = FALSE; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1253 } else if (!forced) { |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1254 if (maildir_sync_quick_check(ctx->mbox, |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1255 ctx->new_dir, ctx->cur_dir, |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1256 &new_changed, &cur_changed) < 0) |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1257 return -1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1258 |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1259 if (!new_changed && !cur_changed) |
3579
09565508b8ba
We were forcing a maildir resync when it hadn't changed at all.
Timo Sirainen <tss@iki.fi>
parents:
3563
diff
changeset
|
1260 return 1; |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1261 } else { |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1262 new_changed = cur_changed = TRUE; |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1263 } |
1947 | 1264 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1265 /* |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1266 Locking, locking, locking.. Wasn't maildir supposed to be lockless? |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1267 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1268 We can get here either as beginning a real maildir sync, or when |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1269 committing changes to maildir but a file was lost (maybe renamed). |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1270 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1271 So, we're going to need two locks. One for index and one for |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1272 uidlist. To avoid deadlocking do the uidlist lock always first. |
2121 | 1273 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1274 uidlist is needed only for figuring out UIDs for newly seen files, |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1275 so theoretically we wouldn't need to lock it unless there are new |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1276 files. It has a few problems though, assuming the index lock didn't |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1277 already protect it (eg. in-memory indexes): |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1278 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1279 1. Just because you see a new file which doesn't exist in uidlist |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1280 file, doesn't mean that the file really exists anymore, or that |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1281 your readdir() lists all new files. Meaning that this is possible: |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1282 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1283 A: opendir(), readdir() -> new file ... |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1284 -- new files are written to the maildir -- |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1285 B: opendir(), readdir() -> new file, lock uidlist, |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1286 readdir() -> another new file, rewrite uidlist, unlock |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1287 A: ... lock uidlist, readdir() -> nothing left, rewrite uidlist, |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1288 unlock |
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
|
1289 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1290 The second time running A didn't see the two new files. To handle |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1291 this correctly, it must not remove the new unseen files from |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1292 uidlist. This is possible to do, but adds extra complexity. |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1293 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1294 2. If another process is rename()ing files while we are |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1295 readdir()ing, it's possible that readdir() never lists some files, |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1296 causing Dovecot to assume they were expunged. In next sync they |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1297 would show up again, but client could have already been notified of |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1298 that and they would show up under new UIDs, so the damage is |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1299 already done. |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1300 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1301 Both of the problems can be avoided if we simply lock the uidlist |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1302 before syncing and keep it until sync is finished. Typically this |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1303 would happen in any case, as there is the index lock.. |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1304 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1305 The second case is still a problem with external changes though, |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1306 because maildir doesn't require any kind of locking. Luckily this |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1307 problem rarely happens except under high amount of modifications. |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1308 */ |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1309 |
3530
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
1310 ctx->partial = !cur_changed; |
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
1311 ret = maildir_uidlist_sync_init(ctx->mbox->uidlist, ctx->partial, |
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
1312 &ctx->uidlist_sync_ctx); |
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
1313 if (ret <= 0) { |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1314 /* failure / timeout. if forced is TRUE, we could still go |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1315 forward and check only for renamed files, but is it worth |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1316 the trouble? .. */ |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1317 return ret; |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1318 } |
2123 | 1319 |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1320 if (!ctx->mbox->syncing_commit) { |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1321 if (maildir_sync_index_begin(ctx->mbox, |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1322 &ctx->index_sync_ctx) < 0) |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1323 return -1; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1324 } |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1325 |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1326 if (new_changed || cur_changed) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1327 /* if we're going to check cur/ dir our current logic requires |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1328 that new/ dir is checked as well. it's a good idea anyway. */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1329 while ((ret = maildir_scan_dir(ctx, TRUE)) > 0) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1330 /* rename()d at least some files, which might have |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1331 caused some other files to be missed. check again |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1332 (see MAILDIR_RENAME_RESCAN_COUNT). */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1333 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1334 if (ret < 0) |
1954 | 1335 return -1; |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1336 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1337 if (cur_changed) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1338 if (maildir_scan_dir(ctx, FALSE) < 0) |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1339 return -1; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1340 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1341 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1342 /* finish uidlist syncing, but keep it still locked */ |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1343 maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx); |
1954 | 1344 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1345 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1346 if (!ctx->mbox->syncing_commit) { |
3530
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
1347 /* NOTE: index syncing here might cause a re-sync due to |
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
1348 files getting lost, so this function might be called |
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
1349 re-entrantly. FIXME: and that breaks in |
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
1350 maildir_uidlist_sync_deinit() */ |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1351 ret = maildir_sync_index(ctx->index_sync_ctx, ctx->partial); |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1352 if (maildir_sync_index_finish(&ctx->index_sync_ctx, |
4774
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
1353 ret < 0, FALSE) < 0) |
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
|
1354 return -1; |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1355 |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1356 if (ret < 0) |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1357 return -1; |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1358 if (ret == 0) |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1359 full_rescan = TRUE; |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1360 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1361 i_assert(maildir_uidlist_is_locked(ctx->mbox->uidlist)); |
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
|
1362 } |
1984 | 1363 |
4238
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1364 ret = maildir_uidlist_sync_deinit(&ctx->uidlist_sync_ctx); |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1365 return ret < 0 ? -1 : (full_rescan ? 0 : 1); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1366 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1367 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1368 int maildir_storage_sync_force(struct maildir_mailbox *mbox) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1369 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1370 struct maildir_sync_context *ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1371 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1372 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1373 ctx = maildir_sync_context_new(mbox); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1374 ret = maildir_sync_context(ctx, TRUE, FALSE); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1375 maildir_sync_deinit(ctx); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1376 return ret < 0 ? -1 : 0; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1377 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1378 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1379 int maildir_sync_last_commit(struct maildir_mailbox *mbox) |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1380 { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1381 struct maildir_sync_context *ctx; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1382 int ret; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1383 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1384 if (mbox->ibox.commit_log_file_seq == 0) |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1385 return 0; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1386 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1387 ctx = maildir_sync_context_new(mbox); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1388 ret = maildir_sync_context(ctx, FALSE, TRUE); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1389 maildir_sync_deinit(ctx); |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1390 return ret < 0 ? -1 : 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1391 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1392 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
1393 struct mailbox_sync_context * |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
1394 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
|
1395 { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1396 struct maildir_mailbox *mbox = (struct maildir_mailbox *)box; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1397 struct maildir_sync_context *ctx; |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
1398 int ret = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1399 |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1400 if (!box->opened) { |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1401 if (index_storage_mailbox_open(&mbox->ibox) < 0) |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1402 return index_mailbox_sync_init(box, 0, TRUE); |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1403 } |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1404 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1405 if ((flags & MAILBOX_SYNC_FLAG_FAST) == 0 || |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1406 mbox->ibox.sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <= |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1407 ioloop_time) { |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1408 mbox->ibox.sync_last_check = ioloop_time; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1409 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1410 ctx = maildir_sync_context_new(mbox); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1411 ret = maildir_sync_context(ctx, FALSE, FALSE); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1412 maildir_sync_deinit(ctx); |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1413 |
4152
e2edd333c473
Added MAILBOX_OPEN_KEEP_LOCKED flag to mailbox opening and implemented it
Timo Sirainen <tss@iki.fi>
parents:
4126
diff
changeset
|
1414 i_assert(!maildir_uidlist_is_locked(mbox->uidlist) || |
e2edd333c473
Added MAILBOX_OPEN_KEEP_LOCKED flag to mailbox opening and implemented it
Timo Sirainen <tss@iki.fi>
parents:
4126
diff
changeset
|
1415 mbox->ibox.keep_locked); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1416 |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1417 if (ret == 0) { |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1418 /* lost some files from new/, see if thery're in cur/ */ |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1419 ret = maildir_storage_sync_force(mbox); |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1420 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1421 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1422 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
1423 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
|
1424 } |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1425 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1426 int maildir_sync_is_synced(struct maildir_mailbox *mbox) |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1427 { |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1428 const char *new_dir, *cur_dir; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
1429 bool new_changed, cur_changed; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3821
diff
changeset
|
1430 int ret; |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1431 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1432 t_push(); |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1433 new_dir = t_strconcat(mbox->path, "/new", NULL); |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1434 cur_dir = t_strconcat(mbox->path, "/cur", NULL); |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1435 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1436 ret = maildir_sync_quick_check(mbox, new_dir, cur_dir, |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1437 &new_changed, &cur_changed); |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1438 t_pop(); |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1439 return ret < 0 ? -1 : (!new_changed && !cur_changed); |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1440 } |