Mercurial > dovecot > original-hg > dovecot-1.2
comparison src/lib-storage/index/maildir/maildir-sync.c @ 1984:9c159272f721 HEAD
syncing fixes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 10 May 2004 02:06:27 +0300 |
parents | 6303ef092c5b |
children | 739b469b99e2 |
comparison
equal
deleted
inserted
replaced
1983:933cab442392 | 1984:9c159272f721 |
---|---|
390 if (dp->d_name[0] == '.') | 390 if (dp->d_name[0] == '.') |
391 continue; | 391 continue; |
392 | 392 |
393 ret = maildir_uidlist_sync_next_pre(ctx->uidlist_sync_ctx, | 393 ret = maildir_uidlist_sync_next_pre(ctx->uidlist_sync_ctx, |
394 dp->d_name); | 394 dp->d_name); |
395 if (ret == 0) | 395 if (ret == 0) { |
396 if (new_dir) | |
397 ctx->ibox->last_new_mtime = 0; | |
398 else | |
399 ctx->ibox->dirty_cur_time = ioloop_time; | |
396 continue; | 400 continue; |
401 } | |
397 if (ret < 0) | 402 if (ret < 0) |
398 break; | 403 break; |
399 | 404 |
400 flags = 0; | 405 flags = 0; |
401 if (move_new) { | 406 if (move_new) { |
404 str_printfa(src, "%s/%s", ctx->new_dir, dp->d_name); | 409 str_printfa(src, "%s/%s", ctx->new_dir, dp->d_name); |
405 str_printfa(dest, "%s/%s", ctx->cur_dir, dp->d_name); | 410 str_printfa(dest, "%s/%s", ctx->cur_dir, dp->d_name); |
406 if (strchr(dp->d_name, ':') == NULL) | 411 if (strchr(dp->d_name, ':') == NULL) |
407 str_append(dest, ":2,"); | 412 str_append(dest, ":2,"); |
408 if (rename(str_c(src), str_c(dest)) == 0) { | 413 if (rename(str_c(src), str_c(dest)) == 0) { |
409 /* we moved it - it's \Recent for use */ | 414 /* we moved it - it's \Recent for us */ |
410 ctx->ibox->dirty_cur_time = ioloop_time; | 415 ctx->ibox->dirty_cur_time = ioloop_time; |
411 flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED | | 416 flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED | |
412 MAILDIR_UIDLIST_REC_FLAG_RECENT; | 417 MAILDIR_UIDLIST_REC_FLAG_RECENT; |
413 } else if (ENOTFOUND(errno)) { | 418 } else if (ENOTFOUND(errno)) { |
414 /* someone else moved it already */ | 419 /* someone else moved it already */ |
493 (ibox->dirty_cur_time != 0 && | 498 (ibox->dirty_cur_time != 0 && |
494 ioloop_time - ibox->dirty_cur_time > MAILDIR_SYNC_SECS)) { | 499 ioloop_time - ibox->dirty_cur_time > MAILDIR_SYNC_SECS)) { |
495 /* cur/ changed, or delayed cur/ check */ | 500 /* cur/ changed, or delayed cur/ check */ |
496 *cur_changed_r = TRUE; | 501 *cur_changed_r = TRUE; |
497 ibox->last_cur_mtime = cur_mtime; | 502 ibox->last_cur_mtime = cur_mtime; |
498 } | 503 |
499 ibox->dirty_cur_time = | 504 ibox->dirty_cur_time = |
500 cur_mtime >= ioloop_time - MAILDIR_SYNC_SECS ? cur_mtime : 0; | 505 cur_mtime >= ioloop_time - MAILDIR_SYNC_SECS ? |
506 cur_mtime : 0; | |
507 } | |
501 | 508 |
502 return 0; | 509 return 0; |
503 } | 510 } |
504 | 511 |
505 static int maildir_sync_index(struct maildir_sync_context *ctx) | 512 static int maildir_sync_index(struct maildir_sync_context *ctx) |
545 /* partial syncing */ | 552 /* partial syncing */ |
546 continue; | 553 continue; |
547 } | 554 } |
548 | 555 |
549 if (seq > hdr->messages_count) { | 556 if (seq > hdr->messages_count) { |
557 if (uid < hdr->next_uid) { | |
558 /* message not in index, but next_uid header | |
559 is updated? shouldn't really happen.. */ | |
560 mail_storage_set_critical(ibox->box.storage, | |
561 "Maildir sync: UID < next_uid " | |
562 "(%u < %u)", uid, hdr->next_uid); | |
563 mail_index_mark_corrupted(ibox->index); | |
564 ret = -1; | |
565 break; | |
566 } | |
567 | |
550 mail_index_append(trans, uid, &seq); | 568 mail_index_append(trans, uid, &seq); |
551 mail_index_update_flags(trans, seq, MODIFY_REPLACE, | 569 mail_index_update_flags(trans, seq, MODIFY_REPLACE, |
552 flags, keywords); | 570 flags, keywords); |
553 continue; | 571 continue; |
554 } | 572 } |
568 if (rec->uid > uid) { | 586 if (rec->uid > uid) { |
569 /* new UID in the middle of the mailbox - | 587 /* new UID in the middle of the mailbox - |
570 shouldn't happen */ | 588 shouldn't happen */ |
571 mail_storage_set_critical(ibox->box.storage, | 589 mail_storage_set_critical(ibox->box.storage, |
572 "Maildir sync: UID inserted in the middle " | 590 "Maildir sync: UID inserted in the middle " |
573 "of mailbox (%u > %u)", rec->uid, uid); | 591 "of mailbox (%u > %u, file = %s)", |
592 rec->uid, uid, filename); | |
574 mail_index_mark_corrupted(ibox->index); | 593 mail_index_mark_corrupted(ibox->index); |
575 ret = -1; | 594 ret = -1; |
576 break; | 595 break; |
577 } | 596 } |
578 | 597 |
584 | 603 |
585 maildir_filename_get_flags(filename, &flags, keywords); | 604 maildir_filename_get_flags(filename, &flags, keywords); |
586 if ((uint8_t)flags != (rec->flags & MAIL_FLAGS_MASK) || | 605 if ((uint8_t)flags != (rec->flags & MAIL_FLAGS_MASK) || |
587 memcmp(keywords, rec->keywords, | 606 memcmp(keywords, rec->keywords, |
588 INDEX_KEYWORDS_BYTE_COUNT) != 0) { | 607 INDEX_KEYWORDS_BYTE_COUNT) != 0) { |
608 /* FIXME: this is wrong if there's syncs later. | |
609 it gets fixed in next sync however.. */ | |
589 mail_index_update_flags(trans, seq, MODIFY_REPLACE, | 610 mail_index_update_flags(trans, seq, MODIFY_REPLACE, |
590 flags, keywords); | 611 flags, keywords); |
591 } | 612 } |
592 } | 613 } |
593 maildir_uidlist_iter_deinit(iter); | 614 maildir_uidlist_iter_deinit(iter); |
654 if (cur_changed) { | 675 if (cur_changed) { |
655 if (maildir_scan_dir(ctx, FALSE) < 0) | 676 if (maildir_scan_dir(ctx, FALSE) < 0) |
656 return -1; | 677 return -1; |
657 } | 678 } |
658 | 679 |
680 /* finish uidlist syncing, but keep it still locked */ | |
681 maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx); | |
682 if (maildir_sync_index(ctx) < 0) | |
683 return -1; | |
684 | |
659 ret = maildir_uidlist_sync_deinit(ctx->uidlist_sync_ctx); | 685 ret = maildir_uidlist_sync_deinit(ctx->uidlist_sync_ctx); |
660 ctx->uidlist_sync_ctx = NULL; | 686 ctx->uidlist_sync_ctx = NULL; |
661 | 687 |
662 if (ret == 0) | |
663 ret = maildir_sync_index(ctx); | |
664 return ret; | 688 return ret; |
665 } | 689 } |
666 | 690 |
667 static int maildir_sync_context_readonly(struct maildir_sync_context *ctx) | 691 static int maildir_sync_context_readonly(struct maildir_sync_context *ctx) |
668 { | 692 { |