comparison src/lib-storage/index/maildir/maildir-sync.c @ 2140:e2cd51b99359 HEAD

"readonly sync" -> "forced sync"
author Timo Sirainen <tss@iki.fi>
date Wed, 16 Jun 2004 03:53:37 +0300
parents e01de478882f
children 9438951e243f
comparison
equal deleted inserted replaced
2139:9f90f83835ae 2140:e2cd51b99359
822 } 822 }
823 823
824 return ret; 824 return ret;
825 } 825 }
826 826
827 static int maildir_sync_context(struct maildir_sync_context *ctx) 827 static int maildir_sync_context(struct maildir_sync_context *ctx, int forced)
828 { 828 {
829 int ret, new_changed, cur_changed; 829 int ret, new_changed, cur_changed;
830 830
831 if (maildir_sync_quick_check(ctx, &new_changed, &cur_changed) < 0) 831 if (!forced) {
832 return -1; 832 if (maildir_sync_quick_check(ctx, &new_changed, &cur_changed) < 0)
833 833 return -1;
834 if (!new_changed && !cur_changed) 834
835 return 0; 835 if (!new_changed && !cur_changed)
836 return 0;
837 } else {
838 new_changed = cur_changed = TRUE;
839 }
836 840
837 /* we have to lock uidlist immediately, otherwise there's race 841 /* we have to lock uidlist immediately, otherwise there's race
838 conditions with other processes who might write older maildir 842 conditions with other processes who might write older maildir
839 file list into uidlist. 843 file list into uidlist.
840 844
841 alternative would be to lock it when new files are found, but 845 alternative would be to lock it when new files are found, but
842 the directory scans _must_ be restarted then */ 846 the directory scans _must_ be restarted then */
843 if ((ret = maildir_uidlist_try_lock(ctx->ibox->uidlist)) <= 0) 847 if ((ret = maildir_uidlist_try_lock(ctx->ibox->uidlist)) < 0)
844 return ret; 848 return ret;
849 if (ret == 0 && !forced) {
850 /* we didn't get a lock, don't do syncing unless we really
851 want to check for expunges or renames. new files won't
852 be added. */
853 return 0;
854 }
845 855
846 ctx->partial = !cur_changed; 856 ctx->partial = !cur_changed;
847 ctx->uidlist_sync_ctx = 857 ctx->uidlist_sync_ctx =
848 maildir_uidlist_sync_init(ctx->ibox->uidlist, ctx->partial); 858 maildir_uidlist_sync_init(ctx->ibox->uidlist, ctx->partial);
849 859
863 ctx->uidlist_sync_ctx = NULL; 873 ctx->uidlist_sync_ctx = NULL;
864 874
865 return ret; 875 return ret;
866 } 876 }
867 877
868 static int maildir_sync_context_readonly(struct maildir_sync_context *ctx) 878 int maildir_storage_sync_force(struct index_mailbox *ibox)
869 {
870 int ret;
871
872 ctx->uidlist_sync_ctx =
873 maildir_uidlist_sync_init(ctx->ibox->uidlist, FALSE);
874
875 if (maildir_scan_dir(ctx, TRUE) < 0)
876 return -1;
877 if (maildir_scan_dir(ctx, FALSE) < 0)
878 return -1;
879
880 maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx);
881 ret = maildir_uidlist_sync_deinit(ctx->uidlist_sync_ctx);
882 ctx->uidlist_sync_ctx = NULL;
883
884 return ret;
885 }
886
887 int maildir_storage_sync_readonly(struct index_mailbox *ibox)
888 { 879 {
889 struct maildir_sync_context *ctx; 880 struct maildir_sync_context *ctx;
890 int ret; 881 int ret;
891 882
892 ctx = maildir_sync_context_new(ibox); 883 ctx = maildir_sync_context_new(ibox);
893 ret = maildir_sync_context_readonly(ctx); 884 ret = maildir_sync_context(ctx, TRUE);
894 maildir_sync_deinit(ctx); 885 maildir_sync_deinit(ctx);
895 return ret; 886 return ret;
896 } 887 }
897 888
898 int maildir_storage_sync(struct mailbox *box, enum mailbox_sync_flags flags) 889 int maildir_storage_sync(struct mailbox *box, enum mailbox_sync_flags flags)
904 if ((flags & MAILBOX_SYNC_FLAG_FAST) == 0 || 895 if ((flags & MAILBOX_SYNC_FLAG_FAST) == 0 ||
905 ibox->sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <= ioloop_time) { 896 ibox->sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <= ioloop_time) {
906 ibox->sync_last_check = ioloop_time; 897 ibox->sync_last_check = ioloop_time;
907 898
908 ctx = maildir_sync_context_new(ibox); 899 ctx = maildir_sync_context_new(ibox);
909 ret = maildir_sync_context(ctx); 900 ret = maildir_sync_context(ctx, FALSE);
910 maildir_sync_deinit(ctx); 901 maildir_sync_deinit(ctx);
911 902
912 if (ret < 0) 903 if (ret < 0)
913 return -1; 904 return -1;
914 } 905 }