comparison src/lib-storage/index/maildir/maildir-sync.c @ 6880:724c8f12eed2 HEAD

maildir_storage_sync_force(): Don't wait on trying to lock uidlist. Just try once and if it fails, find the changed filenames and do nothing else.
author Timo Sirainen <tss@iki.fi>
date Sat, 01 Dec 2007 09:23:21 +0200
parents 0c3ab0aef33c
children b1554dea8ee8
comparison
equal deleted inserted replaced
6879:fed2843b4ab8 6880:724c8f12eed2
206 #define DUPE_LINKS_DELETE_SECS 30 206 #define DUPE_LINKS_DELETE_SECS 30
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 bool partial;
212 211
213 time_t last_touch, last_notify; 212 time_t last_touch, last_notify;
214 213
215 struct maildir_uidlist_sync_ctx *uidlist_sync_ctx; 214 struct maildir_uidlist_sync_ctx *uidlist_sync_ctx;
216 struct maildir_index_sync_context *index_sync_ctx; 215 struct maildir_index_sync_context *index_sync_ctx;
216
217 unsigned int partial:1;
218 unsigned int locked:1;
217 }; 219 };
218 220
219 void maildir_sync_notify(struct maildir_sync_context *ctx) 221 void maildir_sync_notify(struct maildir_sync_context *ctx)
220 { 222 {
221 time_t now; 223 time_t now;
423 t_push(); 425 t_push();
424 src = t_str_new(1024); 426 src = t_str_new(1024);
425 dest = t_str_new(1024); 427 dest = t_str_new(1024);
426 428
427 move_new = new_dir && !mailbox_is_readonly(&ctx->mbox->ibox.box) && 429 move_new = new_dir && !mailbox_is_readonly(&ctx->mbox->ibox.box) &&
428 !ctx->mbox->ibox.keep_recent; 430 !ctx->mbox->ibox.keep_recent && ctx->locked;
429 431
430 errno = 0; 432 errno = 0;
431 for (; (dp = readdir(dirp)) != NULL; errno = 0) { 433 for (; (dp = readdir(dirp)) != NULL; errno = 0) {
432 if (dp->d_name[0] == '.') 434 if (dp->d_name[0] == '.')
433 continue; 435 continue;
752 The second case is still a problem with external changes though, 754 The second case is still a problem with external changes though,
753 because maildir doesn't require any kind of locking. Luckily this 755 because maildir doesn't require any kind of locking. Luckily this
754 problem rarely happens except under high amount of modifications. 756 problem rarely happens except under high amount of modifications.
755 */ 757 */
756 758
757 ctx->partial = !cur_changed; 759 if (!cur_changed || forced) {
758 sync_flags = ctx->partial ? MAILDIR_UIDLIST_SYNC_PARTIAL : 0; 760 ctx->partial = TRUE;
761 sync_flags = MAILDIR_UIDLIST_SYNC_PARTIAL;
762 if (forced)
763 sync_flags |= MAILDIR_UIDLIST_SYNC_FORCE;
764 } else {
765 ctx->partial = FALSE;
766 sync_flags = 0;
767 }
759 ret = maildir_uidlist_sync_init(ctx->mbox->uidlist, sync_flags, 768 ret = maildir_uidlist_sync_init(ctx->mbox->uidlist, sync_flags,
760 &ctx->uidlist_sync_ctx); 769 &ctx->uidlist_sync_ctx);
761 if (ret <= 0) { 770 if (ret <= 0) {
762 /* failure / timeout. if forced is TRUE, we could still go 771 /* failure / timeout */
763 forward and check only for renamed files, but is it worth 772 i_assert(ret < 0 || !forced);
764 the trouble? .. */
765 return ret; 773 return ret;
766 } 774 }
767 775 ctx->locked = maildir_uidlist_is_locked(ctx->mbox->uidlist);
768 if (!ctx->mbox->syncing_commit) { 776
777 if (!ctx->mbox->syncing_commit && ctx->locked) {
769 if (maildir_sync_index_begin(ctx->mbox, ctx, 778 if (maildir_sync_index_begin(ctx->mbox, ctx,
770 &ctx->index_sync_ctx) < 0) 779 &ctx->index_sync_ctx) < 0)
771 return -1; 780 return -1;
772 } 781 }
773 782
795 804
796 /* finish uidlist syncing, but keep it still locked */ 805 /* finish uidlist syncing, but keep it still locked */
797 maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx); 806 maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx);
798 } 807 }
799 808
800 if (!ctx->mbox->syncing_commit) { 809 if (!ctx->mbox->syncing_commit && ctx->locked) {
801 /* NOTE: index syncing here might cause a re-sync due to 810 /* NOTE: index syncing here might cause a re-sync due to
802 files getting lost, so this function might be called 811 files getting lost, so this function might be called
803 re-entrantly. */ 812 re-entrantly. */
804 ret = maildir_sync_index(ctx->index_sync_ctx, ctx->partial); 813 ret = maildir_sync_index(ctx->index_sync_ctx, ctx->partial);
805 if (maildir_sync_index_finish(&ctx->index_sync_ctx, 814 if (maildir_sync_index_finish(&ctx->index_sync_ctx,