Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/maildir/maildir-sync.c @ 5950:49aebb3028f7 HEAD
Added support for updating uidlist record extensions.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 12 Jul 2007 02:42:32 +0300 |
parents | b9865213da42 |
children | 272796cfee66 |
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" |
5926
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
179 #include "nfs-workarounds.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
180 #include "maildir-storage.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 #include "maildir-uidlist.h" |
5899
f29b93c0519c
Moved maildir filename related functions to maildir-filename.c
Timo Sirainen <tss@iki.fi>
parents:
5850
diff
changeset
|
182 #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
|
183 #include "maildir-sync.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 #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
|
186 #include <stddef.h> |
5588
6c89106dee21
Keyword characters weren't sorted in the maildir filename.
Timo Sirainen <tss@iki.fi>
parents:
5582
diff
changeset
|
187 #include <stdlib.h> |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 #include <unistd.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 #include <dirent.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 #include <sys/stat.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 #define MAILDIR_FILENAME_FLAG_FOUND 128 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 |
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
|
194 /* 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 #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
|
201 |
5397
3a0964ac3a5c
comment/duplicate link handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
5392
diff
changeset
|
202 /* 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
|
203 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
|
204 #define MAILDIR_SCAN_DIR_MAX_COUNT 5 |
0c8705aad54c
Avoid infinite looping when buggy filesystems.
Timo Sirainen <tss@iki.fi>
parents:
5390
diff
changeset
|
205 |
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
|
206 #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
|
207 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 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
|
209 struct maildir_mailbox *mbox; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 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
|
211 bool partial; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 |
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
|
213 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
|
214 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
215 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
|
216 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
|
217 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
5918
diff
changeset
|
219 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
|
220 { |
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 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
|
222 |
5390
4eeec560df01
If saving to maildir causes flag/expunge syncs, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
5388
diff
changeset
|
223 if (ctx == NULL) { |
4eeec560df01
If saving to maildir causes flag/expunge syncs, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
5388
diff
changeset
|
224 /* 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
|
225 maildir_sync_context, */ |
4eeec560df01
If saving to maildir causes flag/expunge syncs, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
5388
diff
changeset
|
226 return; |
4eeec560df01
If saving to maildir causes flag/expunge syncs, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
5388
diff
changeset
|
227 } |
4eeec560df01
If saving to maildir causes flag/expunge syncs, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
5388
diff
changeset
|
228 |
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 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
|
230 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
|
231 (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
|
232 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
|
233 } |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
234 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
|
235 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
|
236 |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
237 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
|
238 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
|
239 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
|
240 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
|
241 } |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
242 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
|
243 } |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
244 } |
7d45edb81fe4
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
245 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 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
|
247 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
|
248 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 struct maildir_sync_context *ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 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
|
252 ctx->mbox = mbox; |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
253 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
|
254 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
|
255 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
|
256 ctx->last_notify = ioloop_time; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 return ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
260 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
|
261 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 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
|
263 (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
|
264 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
|
265 (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
|
266 TRUE, FALSE); |
615b7738a62f
Saving mails could have skipped over transactions, which caused different
Timo Sirainen <tss@iki.fi>
parents:
4612
diff
changeset
|
267 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
270 static int maildir_fix_duplicate(struct maildir_sync_context *ctx, |
5910 | 271 const char *dir, const char *fname2) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 { |
5910 | 273 const char *fname1, *path1, *path2; |
274 const char *new_fname, *new_path; | |
275 struct stat st1, st2; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 int ret = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 |
5910 | 278 fname1 = maildir_uidlist_sync_get_full_filename(ctx->uidlist_sync_ctx, |
279 fname2); | |
280 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
|
281 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 t_push(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 |
5910 | 284 path1 = t_strconcat(dir, "/", fname1, NULL); |
285 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
|
286 |
5910 | 287 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
|
288 /* 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
|
289 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
|
290 t_pop(); |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
291 return 0; |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
292 } |
5910 | 293 if (st1.st_ino == st2.st_ino && |
294 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
|
295 /* 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
|
296 between stat() calls, or that the files were link()ed. */ |
5910 | 297 if (st1.st_nlink > 1 && st2.st_nlink == st1.st_nlink && |
298 st1.st_ctime == st2.st_ctime && | |
299 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
|
300 /* 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
|
301 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
|
302 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
|
303 |
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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 happening) */ |
5910 | 310 if (unlink(path2) == 0) |
311 i_warning("Unlinked a duplicate: %s", path2); | |
312 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
|
313 mail_storage_set_critical( |
5910 | 314 &ctx->mbox->storage->storage, |
315 "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
|
316 } |
293bc7d1062f
If we find duplicate hard links which haven't changed for 30 secs, unlink()
Timo Sirainen <tss@iki.fi>
parents:
5397
diff
changeset
|
317 } |
4397
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
318 t_pop(); |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
319 return 0; |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
320 } |
5cbabd4ccd9c
Don't go fixing duplicate maildir filenames without properly checking that
Timo Sirainen <tss@iki.fi>
parents:
4238
diff
changeset
|
321 |
5904
62ceb6b2b20d
Renamed maildir_generate_tmp_filename() to maildir_filename_generate(). Also
Timo Sirainen <tss@iki.fi>
parents:
5901
diff
changeset
|
322 new_fname = maildir_filename_generate(); |
5910 | 323 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
|
324 |
5910 | 325 if (rename(path2, new_path) == 0) |
326 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
|
327 else if (errno != ENOENT) { |
5910 | 328 mail_storage_set_critical(&ctx->mbox->storage->storage, |
5582 | 329 "Couldn't fix a duplicate: rename(%s, %s) failed: %m", |
5910 | 330 path2, new_path); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 t_pop(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
335 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
337 |
5926
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
338 static int |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
339 maildir_stat(struct maildir_mailbox *mbox, const char *path, struct stat *st_r) |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
340 { |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
341 if (nfs_safe_stat(path, st_r) == 0) |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
342 return 0; |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
343 if (errno == ENOENT) { |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
344 /* if mailbox gets deleted under us, don't log an error */ |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
345 mbox->ibox.mailbox_deleted = TRUE; |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
346 return -1; |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
347 } |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
348 |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
349 mail_storage_set_critical(mbox->ibox.box.storage, |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
350 "stat(%s) failed: %m", path); |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
351 return -1; |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
352 } |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
353 |
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
|
354 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
|
355 { |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5443
diff
changeset
|
356 struct mail_storage *storage = &ctx->mbox->storage->storage; |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
357 const char *path; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
358 DIR *dirp; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
359 string_t *src, *dest; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 struct dirent *dp; |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
361 struct stat st; |
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
|
362 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
|
363 unsigned int i = 0, move_count = 0; |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
364 time_t now; |
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
|
365 int ret = 1; |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
366 bool move_new, check_touch, dir_changed = FALSE; |
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
|
367 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
368 path = new_dir ? ctx->new_dir : ctx->cur_dir; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
369 dirp = opendir(path); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
370 if (dirp == NULL) { |
5926
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
371 if (errno == ENOENT) { |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
372 ctx->mbox->ibox.mailbox_deleted = TRUE; |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
373 return -1; |
095b3adc537b
Handle mailbox deletions while syncing silently.
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
374 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 mail_storage_set_critical(storage, |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
376 "opendir(%s) failed: %m", path); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
377 return -1; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
378 } |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
379 |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
380 #ifdef HAVE_DIRFD |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
381 if (fstat(dirfd(dirp), &st) < 0) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
382 mail_storage_set_critical(storage, |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
383 "fstat(%s) failed: %m", path); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
384 (void)closedir(dirp); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
385 return -1; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
386 } |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
387 #else |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
388 if (maildir_stat(ctx->mbox, path, &st) < 0) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
389 (void)closedir(dirp); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 } |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
392 #endif |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
393 |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
394 now = time(NULL); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
395 if (new_dir) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
396 ctx->mbox->maildir_hdr.new_check_time = now; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
397 ctx->mbox->maildir_hdr.new_mtime = st.st_mtime; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
398 #ifdef HAVE_STAT_TV_NSEC |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
399 ctx->mbox->maildir_hdr.new_mtime_nsecs = st.st_mtim.tv_nsec; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
400 #else |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
401 ctx->mbox->maildir_hdr.new_mtime_nsecs = 0; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
402 #endif |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
403 } else { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
404 ctx->mbox->maildir_hdr.cur_check_time = now; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
405 ctx->mbox->maildir_hdr.cur_mtime = st.st_mtime; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
406 #ifdef HAVE_STAT_TV_NSEC |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
407 ctx->mbox->maildir_hdr.cur_mtime_nsecs = st.st_mtim.tv_nsec; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
408 #else |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
409 ctx->mbox->maildir_hdr.cur_mtime_nsecs = 0; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
410 #endif |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
411 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 |
2121 | 413 t_push(); |
414 src = t_str_new(1024); | |
415 dest = t_str_new(1024); | |
416 | |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
417 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
|
418 !ctx->mbox->ibox.keep_recent; |
5911
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
419 |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
420 errno = 0; |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
421 for (; (dp = readdir(dirp)) != NULL; errno = 0) { |
2258
087a43e29492
No maildir filename checking after all.
Timo Sirainen <tss@iki.fi>
parents:
2256
diff
changeset
|
422 if (dp->d_name[0] == '.') |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
423 continue; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
424 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
425 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
|
426 dp->d_name); |
1984 | 427 if (ret == 0) { |
2038
df504dad3aec
Recent flag fixes. Should work perfectly now with maildir.
Timo Sirainen <tss@iki.fi>
parents:
2037
diff
changeset
|
428 /* 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
|
429 later in next sync. */ |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
430 dir_changed = TRUE; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
431 continue; |
1984 | 432 } |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
433 if (ret < 0) |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
434 break; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1970
diff
changeset
|
435 |
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
|
436 check_touch = FALSE; |
1947 | 437 flags = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 if (move_new) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 str_truncate(src, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
440 str_truncate(dest, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
441 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
|
442 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
|
443 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
|
444 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
|
445 } |
1947 | 446 if (rename(str_c(src), str_c(dest)) == 0) { |
1984 | 447 /* we moved it - it's \Recent for us */ |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
448 dir_changed = TRUE; |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
449 move_count++; |
1947 | 450 flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED | |
451 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
452 } else if (ENOTFOUND(errno)) { | |
453 /* someone else moved it already */ | |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
454 dir_changed = TRUE; |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
455 move_count++; |
1947 | 456 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
|
457 } 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
|
458 /* 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
|
459 leave here */ |
1947 | 460 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | |
461 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 move_new = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 } else { |
1947 | 464 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | |
465 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
466 mail_storage_set_critical(storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 "rename(%s, %s) failed: %m", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 str_c(src), str_c(dest)); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 } |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
470 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
|
471 maildir_sync_notify(ctx); |
1947 | 472 } else if (new_dir) { |
473 flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | | |
474 MAILDIR_UIDLIST_REC_FLAG_RECENT; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
475 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 |
5914
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
477 i++; |
ae731dbf3a6f
Sync index changes while iterating through uidlist entries. This avoids
Timo Sirainen <tss@iki.fi>
parents:
5912
diff
changeset
|
478 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
|
479 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
|
480 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
481 ret = maildir_uidlist_sync_next(ctx->uidlist_sync_ctx, |
1947 | 482 dp->d_name, flags); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
483 if (ret <= 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
484 if (ret < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
485 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
486 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
487 /* possibly duplicate - try fixing it */ |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
488 if (maildir_fix_duplicate(ctx, path, dp->d_name) < 0) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
489 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
490 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
491 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
492 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
493 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
494 |
5911
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
495 if (errno != 0) { |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
496 mail_storage_set_critical(storage, |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
497 "readdir(%s) failed: %m", path); |
5911
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
498 ret = -1; |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
499 } |
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
500 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 if (closedir(dirp) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
502 mail_storage_set_critical(storage, |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
503 "closedir(%s) failed: %m", path); |
5911
8bb5c7a69405
If readdir() or closedir() fails, return failure.
Timo Sirainen <tss@iki.fi>
parents:
5910
diff
changeset
|
504 ret = -1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
505 } |
2121 | 506 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
507 if (dir_changed) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
508 if (new_dir) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
509 ctx->mbox->maildir_hdr.new_mtime = now; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
510 else |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
511 ctx->mbox->maildir_hdr.cur_mtime = now; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
512 } |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
513 |
2121 | 514 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
|
515 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
|
516 (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
|
517 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
518 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
519 static int maildir_header_refresh(struct maildir_mailbox *mbox) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
520 { |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
521 const void *data; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
522 size_t data_size; |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
523 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
524 if (mail_index_refresh(mbox->ibox.index) < 0) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
525 mail_storage_set_index_error(&mbox->ibox); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
526 return -1; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
527 } |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
528 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
529 if (mail_index_get_header_ext(mbox->ibox.view, mbox->maildir_ext_id, |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
530 &data, &data_size) < 0) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
531 mail_storage_set_index_error(&mbox->ibox); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
532 return -1; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
533 } |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
534 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
535 if (data_size == 0) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
536 /* doesn't exist */ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
537 return 0; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
538 } |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4774
diff
changeset
|
539 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
540 if (data_size != sizeof(mbox->maildir_hdr)) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
541 i_warning("Maildir %s: Invalid header record size", mbox->path); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
542 else |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
543 memcpy(&mbox->maildir_hdr, data, sizeof(mbox->maildir_hdr)); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
544 return 0; |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
545 } |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
546 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
547 static int maildir_sync_quick_check(struct maildir_mailbox *mbox, |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
548 const char *new_dir, const char *cur_dir, |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
549 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
|
550 { |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
551 #ifdef HAVE_STAT_TV_NSEC |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
552 # define DIR_NSECS_CHANGED(st, hdr, name) \ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
553 ((st).st_mtim.tv_nsec != (hdr)->name ## _mtime_nsecs) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
554 #else |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
555 # define DIR_NSECS_CHANGED(st, hdr, name) 0 |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
556 #endif |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
557 |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
558 #define DIR_DELAYED_REFRESH(hdr, name) \ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
559 ((hdr)->name ## _check_time <= \ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
560 (hdr)->name ## _mtime + MAILDIR_SYNC_SECS && \ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
561 (hdr)->name ## _check_time < ioloop_time - MAILDIR_SYNC_SECS) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
562 |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
563 #define DIR_MTIME_CHANGED(st, hdr, name) \ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
564 ((st).st_mtime != (hdr)->name ## _mtime || \ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
565 DIR_NSECS_CHANGED(st, hdr, name)) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
566 |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
567 struct maildir_index_header *hdr = &mbox->maildir_hdr; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
568 struct stat new_st, cur_st; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
569 bool refreshed = FALSE, check_new = FALSE, check_cur = FALSE; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
570 |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
571 if (mbox->maildir_hdr.new_mtime == 0) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
572 maildir_header_refresh(mbox); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
573 if (mbox->maildir_hdr.new_mtime == 0) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
574 /* first sync */ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
575 *new_changed_r = *cur_changed_r = TRUE; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
576 return 0; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
577 } |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
578 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
579 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
580 *new_changed_r = *cur_changed_r = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
581 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
582 /* try to avoid stat()ing by first checking delayed changes */ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
583 if (DIR_DELAYED_REFRESH(hdr, new) || |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
584 DIR_DELAYED_REFRESH(hdr, cur)) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
585 /* refresh index and try again */ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
586 maildir_header_refresh(mbox); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
587 refreshed = TRUE; |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
588 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
589 if (DIR_DELAYED_REFRESH(hdr, new)) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
590 *new_changed_r = TRUE; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
591 if (DIR_DELAYED_REFRESH(hdr, cur)) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
592 *cur_changed_r = TRUE; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
593 if (*new_changed_r && *cur_changed_r) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
594 return 0; |
1954 | 595 } |
596 | |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
597 if (!*new_changed_r) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
598 if (maildir_stat(mbox, new_dir, &new_st) < 0) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
599 return -1; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
600 check_new = TRUE; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
601 } |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
602 if (!*cur_changed_r) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
603 if (maildir_stat(mbox, cur_dir, &cur_st) < 0) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
604 return -1; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
605 check_cur = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
606 } |
1954 | 607 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
608 for (;;) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
609 if (check_new) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
610 *new_changed_r = DIR_MTIME_CHANGED(new_st, hdr, new); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
611 if (check_cur) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
612 *cur_changed_r = DIR_MTIME_CHANGED(cur_st, hdr, cur); |
1984 | 613 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
614 if ((!*new_changed_r && !*cur_changed_r) || refreshed) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
615 break; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
616 |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
617 /* refresh index and try again */ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
618 maildir_header_refresh(mbox); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
619 refreshed = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
620 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
621 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
622 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
623 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
624 |
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
|
625 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
|
626 bool sync_last_commit) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
627 { |
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
|
628 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
|
629 int ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
630 |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
631 if (sync_last_commit) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
632 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
|
633 } 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
|
634 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
|
635 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
|
636 &new_changed, &cur_changed) < 0) |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
637 return -1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
638 |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
639 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
|
640 return 1; |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
641 } else { |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
642 new_changed = cur_changed = TRUE; |
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
643 } |
1947 | 644 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
645 /* |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
646 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
|
647 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
648 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
|
649 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
|
650 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
651 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
|
652 uidlist. To avoid deadlocking do the uidlist lock always first. |
2121 | 653 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 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
|
658 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
659 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
|
660 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
|
661 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
|
662 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
663 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
|
664 -- 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
|
665 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
|
666 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
|
667 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
|
668 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
|
669 |
2818
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
670 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
|
671 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
|
672 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
|
673 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
674 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
|
675 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
|
676 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
|
677 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
|
678 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
|
679 already done. |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
680 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
681 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
|
682 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
|
683 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
|
684 |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
685 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
|
686 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
|
687 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
|
688 */ |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
689 |
3530
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
690 ctx->partial = !cur_changed; |
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
691 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
|
692 &ctx->uidlist_sync_ctx); |
e9695ec7925b
Recursive maildir uidlist syncs caused assert crashes. Also did some
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
693 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
|
694 /* 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
|
695 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
|
696 the trouble? .. */ |
a758a5b542bb
Always protect maildir syncing with uidlist lock. Before we only tried to
Timo Sirainen <tss@iki.fi>
parents:
2816
diff
changeset
|
697 return ret; |
2140
e2cd51b99359
"readonly sync" -> "forced sync"
Timo Sirainen <tss@iki.fi>
parents:
2123
diff
changeset
|
698 } |
2123 | 699 |
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
|
700 if (!ctx->mbox->syncing_commit) { |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
5918
diff
changeset
|
701 if (maildir_sync_index_begin(ctx->mbox, 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
|
702 &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
|
703 return -1; |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
704 } |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
705 |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
706 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
|
707 /* 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
|
708 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
|
709 unsigned int count = 0; |
0c8705aad54c
Avoid infinite looping when buggy filesystems.
Timo Sirainen <tss@iki.fi>
parents:
5390
diff
changeset
|
710 |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
711 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
|
712 /* 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
|
713 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
|
714 (see MAILDIR_RENAME_RESCAN_COUNT). */ |
5391
0c8705aad54c
Avoid infinite looping when buggy filesystems.
Timo Sirainen <tss@iki.fi>
parents:
5390
diff
changeset
|
715 if (++count > MAILDIR_SCAN_DIR_MAX_COUNT) |
0c8705aad54c
Avoid infinite looping when buggy filesystems.
Timo Sirainen <tss@iki.fi>
parents:
5390
diff
changeset
|
716 break; |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
717 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
718 if (ret < 0) |
1954 | 719 return -1; |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
720 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
721 if (cur_changed) { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
722 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
|
723 return -1; |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
724 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
725 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
726 /* 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
|
727 maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx); |
1954 | 728 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
729 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
730 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
|
731 /* 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
|
732 files getting lost, so this function might be called |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5926
diff
changeset
|
733 re-entrantly. */ |
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
|
734 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
|
735 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
|
736 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
|
737 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
|
738 |
3c8b191b0019
Adding mail to index while saving it had a race condition. Fixing it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4199
diff
changeset
|
739 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
|
740 return -1; |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
741 if (ret == 0) |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
742 full_rescan = TRUE; |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
743 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
744 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
|
745 } |
1984 | 746 |
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
|
747 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
|
748 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
|
749 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
750 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
751 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
|
752 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
753 struct maildir_sync_context *ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
754 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
755 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
756 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
|
757 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
|
758 maildir_sync_deinit(ctx); |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
759 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
|
760 } |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
761 |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
762 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
|
763 { |
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
764 struct maildir_sync_context *ctx; |
5950
49aebb3028f7
Added support for updating uidlist record extensions.
Timo Sirainen <tss@iki.fi>
parents:
5927
diff
changeset
|
765 int ret = 0; |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
766 |
5950
49aebb3028f7
Added support for updating uidlist record extensions.
Timo Sirainen <tss@iki.fi>
parents:
5927
diff
changeset
|
767 if (mbox->ibox.commit_log_file_seq != 0) { |
49aebb3028f7
Added support for updating uidlist record extensions.
Timo Sirainen <tss@iki.fi>
parents:
5927
diff
changeset
|
768 ctx = maildir_sync_context_new(mbox); |
49aebb3028f7
Added support for updating uidlist record extensions.
Timo Sirainen <tss@iki.fi>
parents:
5927
diff
changeset
|
769 ret = maildir_sync_context(ctx, FALSE, TRUE); |
49aebb3028f7
Added support for updating uidlist record extensions.
Timo Sirainen <tss@iki.fi>
parents:
5927
diff
changeset
|
770 maildir_sync_deinit(ctx); |
49aebb3028f7
Added support for updating uidlist record extensions.
Timo Sirainen <tss@iki.fi>
parents:
5927
diff
changeset
|
771 } |
3447
96de02ea7482
Keywords are stored in maildir filename and maildir-keywords file
Timo Sirainen <tss@iki.fi>
parents:
3446
diff
changeset
|
772 |
5950
49aebb3028f7
Added support for updating uidlist record extensions.
Timo Sirainen <tss@iki.fi>
parents:
5927
diff
changeset
|
773 if (ret == 0) { |
49aebb3028f7
Added support for updating uidlist record extensions.
Timo Sirainen <tss@iki.fi>
parents:
5927
diff
changeset
|
774 if (maildir_uidlist_update(mbox->uidlist) < 0) |
49aebb3028f7
Added support for updating uidlist record extensions.
Timo Sirainen <tss@iki.fi>
parents:
5927
diff
changeset
|
775 ret = -1; |
49aebb3028f7
Added support for updating uidlist record extensions.
Timo Sirainen <tss@iki.fi>
parents:
5927
diff
changeset
|
776 } |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
777 return ret < 0 ? -1 : 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
778 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
779 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
780 struct mailbox_sync_context * |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
781 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
|
782 { |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
783 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
|
784 struct maildir_sync_context *ctx; |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
785 int ret = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
786 |
4894
24afafbfe47b
Make sure the mailbox is opened when transaction is started (fixes deliver).
Timo Sirainen <tss@iki.fi>
parents:
4848
diff
changeset
|
787 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
|
788 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
|
789 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
790 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
|
791 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
|
792 ioloop_time) { |
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
793 mbox->ibox.sync_last_check = ioloop_time; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
794 |
3279
b698ae839a18
Moved mbox/maildir-specific variables from struct index_mailbox to
Timo Sirainen <tss@iki.fi>
parents:
3203
diff
changeset
|
795 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
|
796 ret = maildir_sync_context(ctx, FALSE, FALSE); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
797 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
|
798 |
4152
e2edd333c473
Added MAILBOX_OPEN_KEEP_LOCKED flag to mailbox opening and implemented it
Timo Sirainen <tss@iki.fi>
parents:
4126
diff
changeset
|
799 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
|
800 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
|
801 |
3436
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
802 if (ret == 0) { |
3c51658d6846
We didn't notice if messages were deleted directly from new/.
Timo Sirainen <tss@iki.fi>
parents:
3435
diff
changeset
|
803 /* 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
|
804 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
|
805 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
806 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
807 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2320
diff
changeset
|
808 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
|
809 } |
3472
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
810 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
811 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
|
812 { |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
813 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
|
814 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
|
815 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
|
816 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
817 t_push(); |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
818 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
|
819 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
|
820 |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
821 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
|
822 &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
|
823 t_pop(); |
db29cc6754d5
Store new/ directory's timestamp in sync_size header in index (kludgy..).
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
824 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
|
825 } |