Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/maildir/maildir-sync.c @ 5914:ae731dbf3a6f HEAD
Sync index changes while iterating through uidlist entries. This avoids
unnecessary (and broken) flag updates.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 08 Jul 2007 22:54:55 +0300 |
parents | 53abd603e04b |
children | 126b74419f52 |
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" |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
180 #include "index-sync-changes.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 #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
|
182 #include "maildir-keywords.h" |
5899
f29b93c0519c
Moved maildir filename related functions to maildir-filename.c
Timo Sirainen <tss@iki.fi>
parents:
5850
diff
changeset
|
183 #include "maildir-filename.h" |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
184 #include "maildir-sync.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 #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
|
187 #include <stddef.h> |
5588
6c89106dee21
Keyword characters weren't sorted in the maildir filename.
Timo Sirainen <tss@iki.fi>
parents:
5582
diff
changeset
|
188 #include <stdlib.h> |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 #include <unistd.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 #include <dirent.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 #include <sys/stat.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 #define MAILDIR_FILENAME_FLAG_FOUND 128 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 |
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
|
195 /* 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 #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
|
202 |
5214
4e9d345df846
When syncing huge maildirs check once in a while if we need to update
Timo Sirainen <tss@iki.fi>
parents:
5080
diff
changeset
|
203 /* After moving 100 mails from new/ to cur/, check if we need to touch the |
4e9d345df846
When syncing huge maildirs check once in a while if we need to update
Timo Sirainen <tss@iki.fi>
parents:
5080
diff
changeset
|
204 uidlist lock. */ |
4e9d345df846
When syncing huge maildirs check once in a while if we need to update
Timo Sirainen <tss@iki.fi>
parents:
5080
diff
changeset
|
205 #define MAILDIR_SLOW_MOVE_COUNT 100 |
4e9d345df846
When syncing huge maildirs check once in a while if we need to update
Timo Sirainen <tss@iki.fi>
parents:
5080
diff
changeset
|
206 /* readdir() should be pretty fast to do, but check anyway every 10000 mails |
4e9d345df846
When syncing huge maildirs check once in a while if we need to update
Timo Sirainen <tss@iki.fi>
parents:
5080
diff
changeset
|
207 to see if we need to touch the uidlist lock. */ |
4e9d345df846
When syncing huge maildirs check once in a while if we need to update
Timo Sirainen <tss@iki.fi>
parents:
5080
diff
changeset
|
208 #define MAILDIR_SLOW_CHECK_COUNT 10000 |
4e9d345df846
When syncing huge maildirs check once in a while if we need to update
Timo Sirainen <tss@iki.fi>
parents:
5080
diff
changeset
|
209 |
5397
3a0964ac3a5c
comment/duplicate link handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
5392
diff
changeset
|
210 /* This is mostly to avoid infinite looping when rename() destination already |
3a0964ac3a5c
comment/duplicate link handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
5392
diff
changeset
|
211 exists as the hard link of the file itself. */ |
5391
0c8705aad54c
Avoid infinite looping when buggy filesystems.
Timo Sirainen <tss@iki.fi>
parents:
5390
diff
changeset
|
212 #define MAILDIR_SCAN_DIR_MAX_COUNT 5 |
0c8705aad54c
Avoid infinite looping when buggy filesystems.
Timo Sirainen <tss@iki.fi>
parents:
5390
diff
changeset
|
213 |
5443
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
214 #define DUPE_LINKS_DELETE_SECS 30 |
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
215 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 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
|
217 struct maildir_mailbox *mbox; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 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
|
219 bool partial; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 |
5368
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
221 time_t last_touch, last_notify; |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
222 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
223 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
|
224 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
|
225 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
227 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
|
228 struct maildir_mailbox *mbox; |
5368
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
229 struct maildir_sync_context *maildir_sync_ctx; |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
230 |
2037
8763032d31bd
Set dirty flags through transaction log, not directly. Some other flag
Timo Sirainen <tss@iki.fi>
parents:
2034
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 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
|
235 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
236 struct index_sync_changes_context *sync_changes; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
237 enum mail_flags flags; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
238 ARRAY_TYPE(keyword_indexes) keywords; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
239 |
5562
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
240 uint32_t seq, uid; |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
241 |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
242 bool changed; |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
243 }; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
244 |
3775
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
245 struct maildir_keywords_sync_ctx * |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
246 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
|
247 { |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
248 return ctx->keywords_sync_ctx; |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
249 } |
8321e6191275
maildir_copy_with_hardlinks works again.
Timo Sirainen <tss@iki.fi>
parents:
3583
diff
changeset
|
250 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
251 static int maildir_expunge(struct maildir_mailbox *mbox, const char *path, |
5562
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
252 struct maildir_index_sync_context *ctx) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 { |
5562
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
254 struct mailbox *box = &mbox->ibox.box; |
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
255 |
1955 | 256 if (unlink(path) == 0) { |
5562
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
257 if (box->v.sync_notify != NULL) { |
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
258 box->v.sync_notify(box, ctx->uid, |
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
259 MAILBOX_SYNC_TYPE_EXPUNGE); |
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
260 } |
5743
1fa32e040ea5
Treat non-external expunges as requests for expunging messages. If it's
Timo Sirainen <tss@iki.fi>
parents:
5708
diff
changeset
|
261 mail_index_expunge(ctx->trans, ctx->seq); |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
262 ctx->changed = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 return 1; |
1955 | 264 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 if (errno == ENOENT) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5443
diff
changeset
|
268 mail_storage_set_critical(&mbox->storage->storage, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 "unlink(%s) failed: %m", path); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
273 static int maildir_sync_flags(struct maildir_mailbox *mbox, const char *path, |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4894
diff
changeset
|
274 struct maildir_index_sync_context *ctx) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 { |
5562
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
276 struct mailbox *box = &mbox->ibox.box; |
4450
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
277 const char *dir, *fname, *newfname, *newpath; |
5562
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
278 enum mailbox_sync_type sync_type = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 uint8_t flags8; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 |
4450
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
281 fname = strrchr(path, '/'); |
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
282 i_assert(fname != NULL); |
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
283 fname++; |
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
284 dir = t_strdup_until(path, fname); |
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
285 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
286 /* get the current flags and keywords */ |
5901
3764697932ae
maildir_filename_get_flags() returns void now.
Timo Sirainen <tss@iki.fi>
parents:
5899
diff
changeset
|
287 maildir_filename_get_flags(ctx->keywords_sync_ctx, |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
288 fname, &ctx->flags, &ctx->keywords); |
3446
113c888cdca1
Merge changes from multiple index sync records into one before actually
Timo Sirainen <tss@iki.fi>
parents:
3436
diff
changeset
|
289 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
290 /* apply changes */ |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
291 flags8 = ctx->flags; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
292 index_sync_changes_apply(ctx->sync_changes, NULL, |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
293 &flags8, &ctx->keywords, &sync_type); |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
294 ctx->flags = flags8; |
4450
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
295 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
296 /* and try renaming with the new name */ |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
297 newfname = maildir_filename_set_flags(ctx->keywords_sync_ctx, fname, |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
298 ctx->flags, &ctx->keywords); |
4450
14b10f7ea70e
Don't break if mailbox path contains ':' characters.
Timo Sirainen <tss@iki.fi>
parents:
4397
diff
changeset
|
299 newpath = t_strconcat(dir, newfname, NULL); |
1955 | 300 if (rename(path, newpath) == 0) { |
5562
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
301 if (box->v.sync_notify != NULL) |
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
302 box->v.sync_notify(box, ctx->uid, sync_type); |
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
303 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
304 ctx->changed = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 return 1; |
1955 | 306 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 if (errno == ENOENT) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
310 if (!ENOSPACE(errno) && errno != EACCES) { |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
311 mail_storage_set_critical(&mbox->storage->storage, |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
312 "rename(%s, %s) failed: %m", path, newpath); |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
313 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
316 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
317 static void maildir_sync_notify(struct maildir_sync_context *ctx) |
5368
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
318 { |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
319 time_t now; |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
320 |
5390
4eeec560df01
If saving to maildir causes flag/expunge syncs, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
5388
diff
changeset
|
321 if (ctx == NULL) { |
4eeec560df01
If saving to maildir causes flag/expunge syncs, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
5388
diff
changeset
|
322 /* we got here from maildir-save.c. it has no |
4eeec560df01
If saving to maildir causes flag/expunge syncs, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
5388
diff
changeset
|
323 maildir_sync_context, */ |
4eeec560df01
If saving to maildir causes flag/expunge syncs, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
5388
diff
changeset
|
324 return; |
4eeec560df01
If saving to maildir causes flag/expunge syncs, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
5388
diff
changeset
|
325 } |
4eeec560df01
If saving to maildir causes flag/expunge syncs, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
5388
diff
changeset
|
326 |
5368
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
327 now = time(NULL); |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
328 if (now - ctx->last_touch > MAILDIR_LOCK_TOUCH_SECS) { |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
329 (void)maildir_uidlist_lock_touch(ctx->mbox->uidlist); |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
330 ctx->last_touch = now; |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
331 } |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
332 if (now - ctx->last_notify > MAIL_STORAGE_STAYALIVE_SECS) { |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
333 struct mailbox *box = &ctx->mbox->ibox.box; |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
334 |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
335 if (box->storage->callbacks->notify_ok != NULL) { |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
336 box->storage->callbacks-> |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
337 notify_ok(box, "Hang in there..", |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
338 box->storage->callback_context); |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
339 } |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
340 ctx->last_notify = now; |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
341 } |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
342 } |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
343 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
344 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
|
345 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
|
346 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
347 struct maildir_sync_context *ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
348 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
349 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
|
350 ctx->mbox = mbox; |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
351 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
|
352 ctx->cur_dir = t_strconcat(mbox->path, "/cur", NULL); |
5368
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
353 ctx->last_touch = ioloop_time; |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
354 ctx->last_notify = ioloop_time; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
355 return ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
356 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
357 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
358 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
|
359 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 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
|
361 (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
|
362 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
|
363 (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
|
364 TRUE, FALSE); |
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
365 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
366 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
367 |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
368 static int maildir_fix_duplicate(struct maildir_sync_context *ctx, |
5910 | 369 const char *dir, const char *fname2) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
370 { |
5910 | 371 const char *fname1, *path1, *path2; |
372 const char *new_fname, *new_path; | |
373 struct stat st1, st2; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 int ret = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 |
5910 | 376 fname1 = maildir_uidlist_sync_get_full_filename(ctx->uidlist_sync_ctx, |
377 fname2); | |
378 i_assert(fname1 != NULL); | |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
379 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 t_push(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
381 |
5910 | 382 path1 = t_strconcat(dir, "/", fname1, NULL); |
383 path2 = t_strconcat(dir, "/", fname2, NULL); | |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
384 |
5910 | 385 if (stat(path1, &st1) < 0 || stat(path2, &st2) < 0) { |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
386 /* 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
|
387 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
|
388 t_pop(); |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
389 return 0; |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
390 } |
5910 | 391 if (st1.st_ino == st2.st_ino && |
392 CMP_DEV_T(st1.st_dev, st2.st_dev)) { | |
5397
3a0964ac3a5c
comment/duplicate link handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
5392
diff
changeset
|
393 /* Files are the same. this means either a race condition |
5443
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
394 between stat() calls, or that the files were link()ed. */ |
5910 | 395 if (st1.st_nlink > 1 && st2.st_nlink == st1.st_nlink && |
396 st1.st_ctime == st2.st_ctime && | |
397 st1.st_ctime < ioloop_time - DUPE_LINKS_DELETE_SECS) { | |
5443
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
398 /* The file has hard links and it hasn't had any |
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
399 changes (such as renames) for a while, so this |
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
400 isn't a race condition. |
5392
9a8402768b42
If duplicate links are found, rename() one over the other to get rid of
Timo Sirainen <tss@iki.fi>
parents:
5391
diff
changeset
|
401 |
5443
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
402 rename()ing one file on top of the other would fix |
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
403 this safely, except POSIX decided that rename() |
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
404 doesn't work that way. So we'll have unlink() one |
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
405 and hope that another process didn't just decide to |
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
406 unlink() the other (uidlist lock prevents this from |
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
407 happening) */ |
5910 | 408 if (unlink(path2) == 0) |
409 i_warning("Unlinked a duplicate: %s", path2); | |
410 else { | |
5443
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
411 mail_storage_set_critical( |
5910 | 412 &ctx->mbox->storage->storage, |
413 "unlink(%s) failed: %m", path2); | |
5443
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
414 } |
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
415 } |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
416 t_pop(); |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
417 return 0; |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
418 } |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
419 |
5904
62ceb6b2b20d
Renamed maildir_generate_tmp_filename() to maildir_filename_generate(). Also
Timo Sirainen <tss@iki.fi>
parents:
5901
diff
changeset
|
420 new_fname = maildir_filename_generate(); |
5910 | 421 new_path = t_strconcat(ctx->mbox->path, "/new/", new_fname, NULL); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
422 |
5910 | 423 if (rename(path2, new_path) == 0) |
424 i_warning("Fixed a duplicate: %s -> %s", path2, new_fname); | |
5392
9a8402768b42
If duplicate links are found, rename() one over the other to get rid of
Timo Sirainen <tss@iki.fi>
parents:
5391
diff
changeset
|
425 else if (errno != ENOENT) { |
5910 | 426 mail_storage_set_critical(&ctx->mbox->storage->storage, |
5582 | 427 "Couldn't fix a duplicate: rename(%s, %s) failed: %m", |
5910 | 428 path2, new_path); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
429 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
430 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
431 t_pop(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
432 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
434 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
435 |
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
|
436 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
|
437 { |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5443
diff
changeset
|
438 struct mail_storage *storage = &ctx->mbox->storage->storage; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 const char *dir; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
440 DIR *dirp; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
441 string_t *src, *dest; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
442 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
|
443 enum maildir_uidlist_rec_flag flags; |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
444 unsigned int i = 0, move_count = 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
|
445 int ret = 1; |
5214
4e9d345df846
When syncing huge maildirs check once in a while if we need to update
Timo Sirainen <tss@iki.fi>
parents:
5080
diff
changeset
|
446 bool move_new, check_touch; |
4e9d345df846
When syncing huge maildirs check once in a while if we need to update
Timo Sirainen <tss@iki.fi>
parents:
5080
diff
changeset
|
447 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 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
|
449 dirp = opendir(dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
450 if (dirp == NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 mail_storage_set_critical(storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 "opendir(%s) failed: %m", dir); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
453 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
454 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 |
2121 | 456 t_push(); |
457 src = t_str_new(1024); | |
458 dest = t_str_new(1024); | |
459 | |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
460 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
|
461 !ctx->mbox->ibox.keep_recent; |
5911
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
462 |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
463 errno = 0; |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
464 for (; (dp = readdir(dirp)) != NULL; errno = 0) { |
2258
087a43e29492
No maildir filename checking after all.
Timo Sirainen <tss@iki.fi>
parents:
2256
diff
changeset
|
465 if (dp->d_name[0] == '.') |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
466 continue; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
468 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
|
469 dp->d_name); |
1984 | 470 if (ret == 0) { |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
471 /* 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
|
472 later in next sync. */ |
1984 | 473 if (new_dir) |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
474 ctx->mbox->last_new_mtime = 0; |
1984 | 475 else |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
476 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
|
477 continue; |
1984 | 478 } |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
479 if (ret < 0) |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
480 break; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
481 |
5214
4e9d345df846
When syncing huge maildirs check once in a while if we need to update
Timo Sirainen <tss@iki.fi>
parents:
5080
diff
changeset
|
482 check_touch = FALSE; |
1947 | 483 flags = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
484 if (move_new) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
485 str_truncate(src, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
486 str_truncate(dest, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
487 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
|
488 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
|
489 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
|
490 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
|
491 } |
1947 | 492 if (rename(str_c(src), str_c(dest)) == 0) { |
1984 | 493 /* we moved it - it's \Recent for us */ |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
494 move_count++; |
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
|
495 ctx->mbox->dirty_cur_time = ioloop_time; |
1947 | 496 flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED | |
497 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
498 } else if (ENOTFOUND(errno)) { | |
499 /* someone else moved it already */ | |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
500 move_count++; |
1947 | 501 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
|
502 } 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
|
503 /* 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
|
504 leave here */ |
1947 | 505 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | |
506 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
507 move_new = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
508 } else { |
1947 | 509 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | |
510 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
511 mail_storage_set_critical(storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
512 "rename(%s, %s) failed: %m", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
513 str_c(src), str_c(dest)); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
514 } |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
515 if ((move_count % MAILDIR_SLOW_MOVE_COUNT) == 0) |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
516 maildir_sync_notify(ctx); |
1947 | 517 } else if (new_dir) { |
518 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | | |
519 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
520 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
521 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
522 i++; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
523 if ((i % MAILDIR_SLOW_CHECK_COUNT) == 0) |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
524 maildir_sync_notify(ctx); |
5214
4e9d345df846
When syncing huge maildirs check once in a while if we need to update
Timo Sirainen <tss@iki.fi>
parents:
5080
diff
changeset
|
525 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
526 ret = maildir_uidlist_sync_next(ctx->uidlist_sync_ctx, |
1947 | 527 dp->d_name, flags); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
528 if (ret <= 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
529 if (ret < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
530 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
531 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
532 /* 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
|
533 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
|
534 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
535 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
536 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
537 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
538 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
539 |
5911
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
540 if (errno != 0) { |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
541 mail_storage_set_critical(storage, |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
542 "readdir(%s) failed: %m", dir); |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
543 ret = -1; |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
544 } |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
545 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
546 if (closedir(dirp) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
547 mail_storage_set_critical(storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
548 "closedir(%s) failed: %m", dir); |
5911
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
549 ret = -1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
550 } |
2121 | 551 |
552 t_pop(); | |
5368
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
553 return ret < 0 ? -1 : |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
554 (move_count <= MAILDIR_RENAME_RESCAN_COUNT ? 0 : 1); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
555 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
556 |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
557 static void |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
558 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
|
559 struct mail_index_header *hdr_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
560 { |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
561 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
|
562 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
|
563 |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
564 /* 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
|
565 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
|
566 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
|
567 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
568 /* 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
|
569 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
|
570 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
|
571 (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
|
572 |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
573 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
|
574 |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
575 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
|
576 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
|
577 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
|
578 |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
579 *hdr_r = *hdr; |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
580 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
|
581 } |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
582 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
583 static int |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
584 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
|
585 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
|
586 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
|
587 { |
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
|
588 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
|
589 struct mail_index_header hdr; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
590 struct stat st; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
591 time_t new_mtime, cur_mtime; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
592 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
593 *new_changed_r = *cur_changed_r = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
594 |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
595 if (stat(new_dir, &st) < 0) { |
5708
7420a96ebc8f
If new/ directory is lost when syncing, assume the mailbox was deleted and
Timo Sirainen <tss@iki.fi>
parents:
5643
diff
changeset
|
596 if (errno == ENOENT) { |
7420a96ebc8f
If new/ directory is lost when syncing, assume the mailbox was deleted and
Timo Sirainen <tss@iki.fi>
parents:
5643
diff
changeset
|
597 /* mailbox was deleted under us. this isn't the only |
7420a96ebc8f
If new/ directory is lost when syncing, assume the mailbox was deleted and
Timo Sirainen <tss@iki.fi>
parents:
5643
diff
changeset
|
598 way it can break, but the most common one. */ |
7420a96ebc8f
If new/ directory is lost when syncing, assume the mailbox was deleted and
Timo Sirainen <tss@iki.fi>
parents:
5643
diff
changeset
|
599 ibox->mailbox_deleted = TRUE; |
7420a96ebc8f
If new/ directory is lost when syncing, assume the mailbox was deleted and
Timo Sirainen <tss@iki.fi>
parents:
5643
diff
changeset
|
600 return -1; |
7420a96ebc8f
If new/ directory is lost when syncing, assume the mailbox was deleted and
Timo Sirainen <tss@iki.fi>
parents:
5643
diff
changeset
|
601 } |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5443
diff
changeset
|
602 mail_storage_set_critical(&mbox->storage->storage, |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
603 "stat(%s) failed: %m", new_dir); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
604 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
605 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
606 new_mtime = st.st_mtime; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
607 |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
608 if (stat(cur_dir, &st) < 0) { |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5443
diff
changeset
|
609 mail_storage_set_critical(&mbox->storage->storage, |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
610 "stat(%s) failed: %m", cur_dir); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
611 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
612 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
613 cur_mtime = st.st_mtime; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
614 |
2893
fd431866c674
mail_index_refresh() isn't public anymore, mail_index_view_open_locked()
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
615 /* 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
|
616 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
|
617 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
618 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
|
619 Pretty ugly.. */ |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
620 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
|
621 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
|
622 (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
|
623 /* 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
|
624 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
|
625 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
|
626 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
|
627 } |
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
|
628 |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
629 maildir_sync_update_from_header(mbox, &hdr); |
1954 | 630 } |
631 | |
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
|
632 /* 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
|
633 it has mails. */ |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
634 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
|
635 ((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
|
636 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
|
637 (!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
|
638 *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
|
639 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
|
640 |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
641 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
|
642 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
|
643 else |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
644 mbox->last_dirty_flags |= MAILDIR_DIRTY_NEW; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
645 } |
1954 | 646 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
647 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
|
648 (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
|
649 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
|
650 /* cur/ changed, or delayed cur/ check */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
651 *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
|
652 mbox->last_cur_mtime = cur_mtime; |
1984 | 653 |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 } else { |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
658 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
|
659 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
|
660 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
661 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
662 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
663 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
664 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
665 |
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
|
666 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
|
667 struct maildir_index_sync_context **ctx_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
668 { |
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
|
669 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
|
670 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
|
671 struct mail_index_view *view; |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5588
diff
changeset
|
672 struct mail_index_transaction *trans; |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
673 |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5588
diff
changeset
|
674 if (mail_index_sync_begin(mbox->ibox.index, &sync_ctx, &view, &trans, |
5779
b25c9ca2142b
mail_index_sync_begin() takes now flags parameter instead of two booleans.
Timo Sirainen <tss@iki.fi>
parents:
5743
diff
changeset
|
675 (uint32_t)-1, (uoff_t)-1, 0) <= 0) { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
676 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
|
677 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
|
678 } |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
679 |
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
|
680 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
|
681 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
|
682 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
|
683 ctx->view = view; |
5643
453128e12b11
mail_index_sync_begin() returns now transaction directly so the syncing code
Timo Sirainen <tss@iki.fi>
parents:
5588
diff
changeset
|
684 ctx->trans = trans; |
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
|
685 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
|
686 maildir_keywords_sync_init(mbox->keywords, mbox->ibox.index); |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
687 |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
688 ctx->sync_changes = index_sync_changes_init(&mbox->ibox, ctx->sync_ctx, |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
689 ctx->view, ctx->trans, |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
690 mbox->ibox.readonly); |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
691 |
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
|
692 *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
|
693 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
|
694 } |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
695 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
696 int maildir_sync_index_finish(struct maildir_index_sync_context **_ctx, |
4774
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
697 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
|
698 { |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
699 struct maildir_index_sync_context *ctx = *_ctx; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
700 struct maildir_mailbox *mbox = ctx->mbox; |
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
|
701 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
|
702 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
703 *_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
|
704 |
4774
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
705 if (ret < 0 || cancel) |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
706 mail_index_sync_rollback(&ctx->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
|
707 else { |
4612
2c033ffc8f6f
maildir_storage_sync_force() crashed if called from mail index sync/expunge
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
708 /* 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
|
709 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
|
710 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
|
711 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
|
712 mbox->syncing_commit = TRUE; |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
713 if (mail_index_sync_commit(&ctx->sync_ctx) < 0) { |
5080 | 714 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
|
715 ret = -1; |
5080 | 716 } else { |
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
|
717 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
|
718 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
|
719 } |
4612
2c033ffc8f6f
maildir_storage_sync_force() crashed if called from mail index sync/expunge
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
720 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
|
721 } |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
722 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
723 maildir_keywords_sync_deinit(ctx->keywords_sync_ctx); |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
724 ctx->keywords_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
|
725 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
726 index_sync_changes_deinit(&ctx->sync_changes); |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
727 i_free(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
|
728 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
|
729 } |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
730 |
5912 | 731 int maildir_sync_index(struct maildir_index_sync_context *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
|
732 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
|
733 { |
5912 | 734 struct maildir_mailbox *mbox = ctx->mbox; |
735 struct mail_index_view *view = ctx->view; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
736 struct maildir_uidlist_iter_ctx *iter; |
5912 | 737 struct mail_index_transaction *trans = ctx->trans; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
738 const struct mail_index_header *hdr; |
5850
f8caf3c6a5a7
Handle UIDVALIDITY changes by resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
739 struct mail_index_header empty_hdr; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
740 const struct mail_index_record *rec; |
5229 | 741 uint32_t seq, uid, prev_uid; |
1954 | 742 enum maildir_uidlist_rec_flag uflags; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
743 const char *filename; |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4450
diff
changeset
|
744 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
|
745 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
|
746 uint64_t value; |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
747 unsigned int changes = 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
|
748 int ret = 0; |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
749 bool expunged, full_rescan = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
750 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
751 i_assert(!mbox->syncing_commit); |
5912 | 752 i_assert(maildir_uidlist_is_locked(ctx->mbox->uidlist)); |
3453 | 753 |
2892
62d53b49110d
Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents:
2877
diff
changeset
|
754 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
|
755 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
|
756 if (uid_validity != hdr->uid_validity && |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
757 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
|
758 /* 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
|
759 reset mailbox so we can add all messages as new */ |
5850
f8caf3c6a5a7
Handle UIDVALIDITY changes by resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
760 i_warning("Maildir %s: UIDVALIDITY changed (%u -> %u)", |
f8caf3c6a5a7
Handle UIDVALIDITY changes by resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
761 mbox->path, hdr->uid_validity, uid_validity); |
f8caf3c6a5a7
Handle UIDVALIDITY changes by resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
762 mail_index_reset(trans); |
3322
49071cc19102
If UIDVALIDITY changes, don't invalidate the whole index. Just expunge all
Timo Sirainen <tss@iki.fi>
parents:
3280
diff
changeset
|
763 |
5850
f8caf3c6a5a7
Handle UIDVALIDITY changes by resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
764 memset(&empty_hdr, 0, sizeof(empty_hdr)); |
f8caf3c6a5a7
Handle UIDVALIDITY changes by resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
765 empty_hdr.next_uid = 1; |
f8caf3c6a5a7
Handle UIDVALIDITY changes by resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
766 hdr = &empty_hdr; |
2050
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
767 } |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
768 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
769 mbox->syncing_commit = TRUE; |
5229 | 770 seq = prev_uid = 0; |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
771 t_array_init(&ctx->keywords, MAILDIR_MAX_KEYWORDS); |
4596
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
772 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
|
773 iter = maildir_uidlist_iter_init(mbox->uidlist); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
774 while (maildir_uidlist_iter_next(iter, &uid, &uflags, &filename)) { |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
775 maildir_filename_get_flags(ctx->keywords_sync_ctx, filename, |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
776 &ctx->flags, &ctx->keywords); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
777 |
5229 | 778 i_assert(uid > prev_uid); |
779 prev_uid = uid; | |
780 | |
4107
d29677c59dc5
Keep \Seen flags privately only in indexes with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
781 /* 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
|
782 at all even for newly seen mails */ |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
783 ctx->flags &= ~mbox->private_flags_mask; |
4107
d29677c59dc5
Keep \Seen flags privately only in indexes with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
784 |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
785 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
|
786 (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
|
787 (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
|
788 /* mail is recent for next session as well */ |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
789 ctx->flags |= MAIL_RECENT; |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
790 } |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
791 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
792 __again: |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
793 ctx->seq = ++seq; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
794 ctx->uid = uid; |
1954 | 795 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
796 if (seq > hdr->messages_count) { |
1984 | 797 if (uid < hdr->next_uid) { |
2053 | 798 /* most likely a race condition: we read the |
799 maildir, then someone else expunged messages | |
800 and committed changes to index. so, this | |
801 message shouldn't actually exist. mark it | |
802 racy and check in next sync. | |
803 | |
804 the difference between this and the later | |
805 check is that this one happens when messages | |
806 are expunged from the end */ | |
807 if ((uflags & | |
2228 | 808 MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { |
809 /* partial syncing */ | |
810 continue; | |
811 } | |
812 if ((uflags & | |
2053 | 813 MAILDIR_UIDLIST_REC_FLAG_RACING) != 0) { |
814 mail_storage_set_critical( | |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5443
diff
changeset
|
815 &mbox->storage->storage, |
2067
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
816 "Maildir %s sync: " |
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
817 "UID < next_uid " |
2053 | 818 "(%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
|
819 mbox->path, uid, hdr->next_uid, |
2067
3f97439ba59e
Path was missing from Maildir sync-errors.
Timo Sirainen <tss@iki.fi>
parents:
2064
diff
changeset
|
820 filename); |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
821 mail_index_mark_corrupted( |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
822 mbox->ibox.index); |
2053 | 823 ret = -1; |
824 break; | |
825 } | |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
826 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
|
827 maildir_uidlist_add_flags(mbox->uidlist, |
2053 | 828 filename, |
829 MAILDIR_UIDLIST_REC_FLAG_RACING); | |
830 | |
831 seq--; | |
832 continue; | |
1984 | 833 } |
834 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
835 mail_index_append(trans, uid, &seq); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
836 mail_index_update_flags(trans, seq, MODIFY_REPLACE, |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
837 ctx->flags); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
838 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
839 if (array_count(&ctx->keywords) > 0) { |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
840 struct mail_keywords *kw; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
841 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
842 kw = mail_index_keywords_create_from_indexes( |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
843 trans, &ctx->keywords); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
844 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
|
845 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
|
846 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
|
847 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
848 continue; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
849 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
850 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
851 if (mail_index_lookup(view, seq, &rec) < 0) { |
5080 | 852 mail_storage_set_index_error(&mbox->ibox); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
853 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
854 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
855 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
856 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
857 if (rec->uid < uid) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
858 /* expunged */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
859 mail_index_expunge(trans, seq); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
860 goto __again; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
861 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
862 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
863 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
|
864 /* 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
|
865 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
|
866 committed changes to index. so, this message |
2053 | 867 shouldn't actually exist. mark it racy and check |
868 in next sync. */ | |
2228 | 869 if ((uflags & |
870 MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { | |
871 /* partial syncing */ | |
872 seq--; | |
873 continue; | |
874 } | |
2053 | 875 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
|
876 mail_storage_set_critical( |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5443
diff
changeset
|
877 &mbox->storage->storage, |
2570 | 878 "Maildir %s sync: " |
879 "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
|
880 "(%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
|
881 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
|
882 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
|
883 ret = -1; |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
884 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
|
885 } |
2053 | 886 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
887 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
|
888 maildir_uidlist_add_flags(mbox->uidlist, filename, |
2053 | 889 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
|
890 |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
891 seq--; |
8078400fe561
Fix bogus "UID inserted in the middle of mailbox" errors
Timo Sirainen <tss@iki.fi>
parents:
2033
diff
changeset
|
892 continue; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
893 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
894 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
895 if (index_sync_changes_read(ctx->sync_changes, rec->uid, |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
896 &expunged) < 0) { |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
897 ret = -1; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
898 break; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
899 } |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
900 |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
901 if (expunged) { |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
902 if (maildir_file_do(ctx->mbox, ctx->uid, |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
903 maildir_expunge, ctx) >= 0) { |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
904 /* successful expunge */ |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
905 mail_index_expunge(trans, ctx->seq); |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
906 } |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
907 if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0) |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
908 maildir_sync_notify(ctx->maildir_sync_ctx); |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
909 continue; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
910 } |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
911 |
4107
d29677c59dc5
Keep \Seen flags privately only in indexes with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
912 /* the private flags are stored only in indexes, keep them */ |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
913 ctx->flags |= rec->flags & mbox->private_flags_mask; |
4107
d29677c59dc5
Keep \Seen flags privately only in indexes with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
914 |
2320
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
915 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
|
916 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
|
917 if (mbox->ibox.keep_recent) { |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
918 ctx->flags |= 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
|
919 } else { |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
920 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
|
921 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
|
922 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
|
923 } |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
924 } |
8a6666a9ac98
Handle recent flags in index file correctly. Fixes recent flag losing when
Timo Sirainen <tss@iki.fi>
parents:
2272
diff
changeset
|
925 |
2228 | 926 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { |
927 /* partial syncing */ | |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
928 if ((ctx->flags & MAIL_RECENT) != 0) { |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
929 /* 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
|
930 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
|
931 make sure. */ |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
932 full_rescan = TRUE; |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
933 } |
2228 | 934 continue; |
935 } | |
936 | |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
937 if (index_sync_changes_have(ctx->sync_changes)) { |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
938 /* apply flag changes to maildir */ |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
939 if (maildir_file_do(ctx->mbox, ctx->uid, |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
940 maildir_sync_flags, ctx) < 0) |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
941 ctx->flags |= MAIL_INDEX_MAIL_FLAG_DIRTY; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
942 if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0) |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
943 maildir_sync_notify(ctx->maildir_sync_ctx); |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
944 } |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
945 |
1956
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
946 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
|
947 /* 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
|
948 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
|
949 continue; |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
950 } |
d6941cd8afdc
Added support for setting dirty flags for messages (TODO: undirty..)
Timo Sirainen <tss@iki.fi>
parents:
1955
diff
changeset
|
951 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
952 if ((ctx->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
|
953 (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
|
954 /* 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
|
955 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
|
956 however.. */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
957 mail_index_update_flags(trans, seq, MODIFY_REPLACE, |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
958 ctx->flags); |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
959 } else if ((ctx->flags & MAIL_RECENT) == 0 && |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
960 (rec->flags & MAIL_RECENT) != 0) { |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
961 /* just remove recent flag */ |
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
962 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
|
963 MAIL_RECENT); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
964 } |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
965 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
966 /* 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
|
967 if (mail_index_lookup_keywords(view, seq, &idx_keywords) < 0) { |
5080 | 968 mail_storage_set_index_error(&mbox->ibox); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
969 ret = -1; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
970 break; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
971 } |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
972 if (!index_keyword_array_cmp(&ctx->keywords, &idx_keywords)) { |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
973 struct mail_keywords *kw; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
974 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
975 kw = mail_index_keywords_create_from_indexes( |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
976 trans, &ctx->keywords); |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
977 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
|
978 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
|
979 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
|
980 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
981 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
982 maildir_uidlist_iter_deinit(iter); |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
983 mbox->syncing_commit = FALSE; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
984 |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
985 if (mbox->ibox.box.v.sync_notify != NULL) |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
986 mbox->ibox.box.v.sync_notify(&mbox->ibox.box, 0, 0); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
987 |
3776
0cae3268c8af
Accidentally had changed !partial-check to partial-check. Because of this
Timo Sirainen <tss@iki.fi>
parents:
3775
diff
changeset
|
988 if (!partial) { |
1954 | 989 /* expunge the rest */ |
990 for (seq++; seq <= hdr->messages_count; seq++) | |
991 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
|
992 |
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
|
993 /* 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
|
994 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
|
995 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
|
996 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
|
997 next_uid = maildir_uidlist_get_next_uid(mbox->uidlist); |
5850
f8caf3c6a5a7
Handle UIDVALIDITY changes by resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5779
diff
changeset
|
998 i_assert(next_uid > prev_uid); |
5369
e897aaa24cdd
If uidlist is deleted and we set the uidvalidity from the index file, set
Timo Sirainen <tss@iki.fi>
parents:
5368
diff
changeset
|
999 if (hdr->next_uid < next_uid) { |
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
|
1000 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
|
1001 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
|
1002 &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
|
1003 } |
1954 | 1004 } |
1005 | |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
1006 if (ctx->changed) |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
1007 mbox->dirty_cur_time = ioloop_time; |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1008 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
|
1009 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
|
1010 |
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1011 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
|
1012 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
|
1013 |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
1014 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
|
1015 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
|
1016 &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
|
1017 } |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
1018 |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1019 /* 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
|
1020 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
|
1021 ((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
|
1022 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
|
1023 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
|
1024 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
|
1025 &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
|
1026 } |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1027 |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1028 if (hdr->uid_validity == 0) { |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1029 /* 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
|
1030 if (maildir_uidlist_update(mbox->uidlist) < 0) |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1031 ret = -1; |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1032 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
|
1033 if (uid_validity == 0) { |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1034 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
|
1035 maildir_uidlist_set_uid_validity(mbox->uidlist, |
5388
ce1bfc98df29
Last fix broke creating new uidlists.
Timo Sirainen <tss@iki.fi>
parents:
5369
diff
changeset
|
1036 uid_validity, 0); |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1037 } |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1038 } 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
|
1039 maildir_uidlist_set_uid_validity(mbox->uidlist, |
5369
e897aaa24cdd
If uidlist is deleted and we set the uidvalidity from the index file, set
Timo Sirainen <tss@iki.fi>
parents:
5368
diff
changeset
|
1040 hdr->uid_validity, |
e897aaa24cdd
If uidlist is deleted and we set the uidvalidity from the index file, set
Timo Sirainen <tss@iki.fi>
parents:
5368
diff
changeset
|
1041 hdr->next_uid); |
2051
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1042 } |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1043 |
596267d8e2e2
Some more UIDVALIDITY issues fixed.
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
1044 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
|
1045 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
|
1046 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
|
1047 &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
|
1048 } |
ee1095ccfd23
Index header changes now go through transaction log. Removed the kludgy
Timo Sirainen <tss@iki.fi>
parents:
2039
diff
changeset
|
1049 |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1050 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
|
1051 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1052 |
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
|
1053 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
|
1054 bool sync_last_commit) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1055 { |
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
|
1056 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
|
1057 int ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1058 |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1059 if (sync_last_commit) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1060 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
|
1061 } 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
|
1062 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
|
1063 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
|
1064 &new_changed, &cur_changed) < 0) |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1065 return -1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1066 |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1067 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
|
1068 return 1; |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1069 } else { |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1070 new_changed = cur_changed = TRUE; |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1071 } |
1947 | 1072 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1073 /* |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1074 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
|
1075 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1076 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
|
1077 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
|
1078 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1079 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
|
1080 uidlist. To avoid deadlocking do the uidlist lock always first. |
2121 | 1081 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1082 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
|
1083 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
|
1084 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
|
1085 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
|
1086 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1087 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
|
1088 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
|
1089 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
|
1090 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1091 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
|
1092 -- 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
|
1093 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
|
1094 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
|
1095 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
|
1096 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
|
1097 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1098 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
|
1099 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
|
1100 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
|
1101 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1102 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
|
1103 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
|
1104 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
|
1105 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
|
1106 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
|
1107 already done. |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1108 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1109 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
|
1110 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
|
1111 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
|
1112 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1113 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
|
1114 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
|
1115 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
|
1116 */ |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1117 |
3530
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
1118 ctx->partial = !cur_changed; |
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
1119 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
|
1120 &ctx->uidlist_sync_ctx); |
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
1121 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
|
1122 /* 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
|
1123 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
|
1124 the trouble? .. */ |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
1125 return ret; |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
1126 } |
2123 | 1127 |
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
|
1128 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
|
1129 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
|
1130 &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
|
1131 return -1; |
5368
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
1132 ctx->index_sync_ctx->maildir_sync_ctx = 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
|
1133 } |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1134 |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1135 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
|
1136 /* 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
|
1137 that new/ dir is checked as well. it's a good idea anyway. */ |
5391
0c8705aad54c
Avoid infinite looping when buggy filesystems.
Timo Sirainen <tss@iki.fi>
parents:
5390
diff
changeset
|
1138 unsigned int count = 0; |
0c8705aad54c
Avoid infinite looping when buggy filesystems.
Timo Sirainen <tss@iki.fi>
parents:
5390
diff
changeset
|
1139 |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1140 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
|
1141 /* 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
|
1142 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
|
1143 (see MAILDIR_RENAME_RESCAN_COUNT). */ |
5391
0c8705aad54c
Avoid infinite looping when buggy filesystems.
Timo Sirainen <tss@iki.fi>
parents:
5390
diff
changeset
|
1144 if (++count > MAILDIR_SCAN_DIR_MAX_COUNT) |
0c8705aad54c
Avoid infinite looping when buggy filesystems.
Timo Sirainen <tss@iki.fi>
parents:
5390
diff
changeset
|
1145 break; |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1146 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1147 if (ret < 0) |
1954 | 1148 return -1; |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1149 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1150 if (cur_changed) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1151 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
|
1152 return -1; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1153 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1154 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1155 /* 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
|
1156 maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx); |
1954 | 1157 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1158 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1159 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
|
1160 /* 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
|
1161 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
|
1162 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
|
1163 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
|
1164 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
|
1165 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
|
1166 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
|
1167 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
|
1168 |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
1169 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
|
1170 return -1; |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1171 if (ret == 0) |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1172 full_rescan = TRUE; |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1173 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1174 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
|
1175 } |
1984 | 1176 |
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
|
1177 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
|
1178 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
|
1179 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1180 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1181 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
|
1182 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1183 struct maildir_sync_context *ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1184 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1185 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1186 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
|
1187 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
|
1188 maildir_sync_deinit(ctx); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1189 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
|
1190 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1191 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1192 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
|
1193 { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1194 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
|
1195 int ret; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1196 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1197 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
|
1198 return 0; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1199 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
1200 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
|
1201 ret = maildir_sync_context(ctx, FALSE, TRUE); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1202 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
|
1203 return ret < 0 ? -1 : 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1204 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1205 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
1206 struct mailbox_sync_context * |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
1207 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
|
1208 { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1209 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
|
1210 struct maildir_sync_context *ctx; |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
1211 int ret = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1212 |
4894
24afafbfe47b
Make sure the mailbox is opened when transaction is started (fixes deliver).
Timo Sirainen <tss@iki.fi>
parents:
4848
diff
changeset
|
1213 if (!box->opened) |
24afafbfe47b
Make sure the mailbox is opened when transaction is started (fixes deliver).
Timo Sirainen <tss@iki.fi>
parents:
4848
diff
changeset
|
1214 index_storage_mailbox_open(&mbox->ibox); |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
1215 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1216 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
|
1217 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
|
1218 ioloop_time) { |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1219 mbox->ibox.sync_last_check = ioloop_time; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1220 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
1221 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
|
1222 ret = maildir_sync_context(ctx, FALSE, FALSE); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1223 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
|
1224 |
4152
e2edd333c473
Added MAILBOX_OPEN_KEEP_LOCKED flag to mailbox opening and implemented it
Timo Sirainen <tss@iki.fi>
parents:
4126
diff
changeset
|
1225 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
|
1226 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
|
1227 |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1228 if (ret == 0) { |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
1229 /* 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
|
1230 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
|
1231 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1232 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1233 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
1234 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
|
1235 } |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1236 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1237 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
|
1238 { |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1239 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
|
1240 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
|
1241 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
|
1242 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1243 t_push(); |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1244 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
|
1245 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
|
1246 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1247 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
|
1248 &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
|
1249 t_pop(); |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
1250 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
|
1251 } |