comparison src/lib-storage/index/maildir/maildir-sync.c @ 6881:b1554dea8ee8 HEAD

If we're doing a fast sync, try only once to lock uidlist.
author Timo Sirainen <tss@iki.fi>
date Sat, 01 Dec 2007 09:48:19 +0200
parents 724c8f12eed2
children 15df8bb27d7a
comparison
equal deleted inserted replaced
6880:724c8f12eed2 6881:b1554dea8ee8
207 207
208 struct maildir_sync_context { 208 struct maildir_sync_context {
209 struct maildir_mailbox *mbox; 209 struct maildir_mailbox *mbox;
210 const char *new_dir, *cur_dir; 210 const char *new_dir, *cur_dir;
211 211
212 enum mailbox_sync_flags flags;
212 time_t last_touch, last_notify; 213 time_t last_touch, last_notify;
213 214
214 struct maildir_uidlist_sync_ctx *uidlist_sync_ctx; 215 struct maildir_uidlist_sync_ctx *uidlist_sync_ctx;
215 struct maildir_index_sync_context *index_sync_ctx; 216 struct maildir_index_sync_context *index_sync_ctx;
216 217
244 ctx->last_notify = now; 245 ctx->last_notify = now;
245 } 246 }
246 } 247 }
247 248
248 static struct maildir_sync_context * 249 static struct maildir_sync_context *
249 maildir_sync_context_new(struct maildir_mailbox *mbox) 250 maildir_sync_context_new(struct maildir_mailbox *mbox,
251 enum mailbox_sync_flags flags)
250 { 252 {
251 struct maildir_sync_context *ctx; 253 struct maildir_sync_context *ctx;
252 254
253 ctx = t_new(struct maildir_sync_context, 1); 255 ctx = t_new(struct maildir_sync_context, 1);
254 ctx->mbox = mbox; 256 ctx->mbox = mbox;
255 ctx->new_dir = t_strconcat(mbox->path, "/new", NULL); 257 ctx->new_dir = t_strconcat(mbox->path, "/new", NULL);
256 ctx->cur_dir = t_strconcat(mbox->path, "/cur", NULL); 258 ctx->cur_dir = t_strconcat(mbox->path, "/cur", NULL);
257 ctx->last_touch = ioloop_time; 259 ctx->last_touch = ioloop_time;
258 ctx->last_notify = ioloop_time; 260 ctx->last_notify = ioloop_time;
261 ctx->flags = flags;
259 return ctx; 262 return ctx;
260 } 263 }
261 264
262 static void maildir_sync_deinit(struct maildir_sync_context *ctx) 265 static void maildir_sync_deinit(struct maildir_sync_context *ctx)
263 { 266 {
762 if (forced) 765 if (forced)
763 sync_flags |= MAILDIR_UIDLIST_SYNC_FORCE; 766 sync_flags |= MAILDIR_UIDLIST_SYNC_FORCE;
764 } else { 767 } else {
765 ctx->partial = FALSE; 768 ctx->partial = FALSE;
766 sync_flags = 0; 769 sync_flags = 0;
770 if ((ctx->flags & MAILBOX_SYNC_FLAG_FAST) != 0)
771 sync_flags |= MAILDIR_UIDLIST_SYNC_TRYLOCK;
767 } 772 }
768 ret = maildir_uidlist_sync_init(ctx->mbox->uidlist, sync_flags, 773 ret = maildir_uidlist_sync_init(ctx->mbox->uidlist, sync_flags,
769 &ctx->uidlist_sync_ctx); 774 &ctx->uidlist_sync_ctx);
770 if (ret <= 0) { 775 if (ret <= 0) {
771 /* failure / timeout */ 776 /* failure / timeout */
830 { 835 {
831 struct maildir_sync_context *ctx; 836 struct maildir_sync_context *ctx;
832 bool lost_files; 837 bool lost_files;
833 int ret; 838 int ret;
834 839
835 ctx = maildir_sync_context_new(mbox); 840 ctx = maildir_sync_context_new(mbox, 0);
836 ret = maildir_sync_context(ctx, TRUE, &lost_files); 841 ret = maildir_sync_context(ctx, TRUE, &lost_files);
837 maildir_sync_deinit(ctx); 842 maildir_sync_deinit(ctx);
838 return ret; 843 return ret;
839 } 844 }
840 845
852 if ((flags & MAILBOX_SYNC_FLAG_FAST) == 0 || 857 if ((flags & MAILBOX_SYNC_FLAG_FAST) == 0 ||
853 mbox->ibox.sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <= 858 mbox->ibox.sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <=
854 ioloop_time) { 859 ioloop_time) {
855 mbox->ibox.sync_last_check = ioloop_time; 860 mbox->ibox.sync_last_check = ioloop_time;
856 861
857 ctx = maildir_sync_context_new(mbox); 862 ctx = maildir_sync_context_new(mbox, flags);
858 ret = maildir_sync_context(ctx, FALSE, &lost_files); 863 ret = maildir_sync_context(ctx, FALSE, &lost_files);
859 maildir_sync_deinit(ctx); 864 maildir_sync_deinit(ctx);
860 865
861 i_assert(!maildir_uidlist_is_locked(mbox->uidlist) || 866 i_assert(!maildir_uidlist_is_locked(mbox->uidlist) ||
862 mbox->ibox.keep_locked); 867 mbox->ibox.keep_locked);