~ubuntu-branches/ubuntu/edgy/dovecot/edgy-security

« back to all changes in this revision

Viewing changes to src/lib-storage/index/maildir/maildir-sync.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-30 15:13:37 UTC
  • mfrom: (1.10.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630151337-l772crcoe5hfd4hw
Tags: 1.0.rc1-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
611
611
                (void)maildir_sync_index_finish(&ctx->index_sync_ctx, TRUE);
612
612
}
613
613
 
614
 
static int maildir_fix_duplicate(struct maildir_mailbox *mbox, const char *dir,
615
 
                                 const char *old_fname)
 
614
static int maildir_fix_duplicate(struct maildir_sync_context *ctx,
 
615
                                 const char *dir, const char *old_fname)
616
616
{
 
617
        struct maildir_mailbox *mbox = ctx->mbox;
 
618
        const char *existing_fname, *existing_path;
617
619
        const char *new_fname, *old_path, *new_path;
 
620
        struct stat st, st2;
618
621
        int ret = 0;
619
622
 
 
623
        existing_fname =
 
624
                maildir_uidlist_sync_get_full_filename(ctx->uidlist_sync_ctx,
 
625
                                                       old_fname);
 
626
        i_assert(existing_fname != NULL);
 
627
 
620
628
        t_push();
621
629
 
 
630
        existing_path = t_strconcat(dir, "/", existing_fname, NULL);
622
631
        old_path = t_strconcat(dir, "/", old_fname, NULL);
 
632
 
 
633
        if (stat(existing_path, &st) < 0 ||
 
634
            stat(old_path, &st2) < 0) {
 
635
                /* most likely the files just don't exist anymore.
 
636
                   don't really care about other errors much. */
 
637
                t_pop();
 
638
                return 0;
 
639
        }
 
640
        if (st.st_ino == st2.st_ino && CMP_DEV_T(st.st_dev, st2.st_dev)) {
 
641
                /* files are the same. this means either a race condition
 
642
                   between stat() calls, or someone has started link()ing the
 
643
                   files. either way there's no data loss if we just leave it
 
644
                   there. */
 
645
                t_pop();
 
646
                return 0;
 
647
        }
 
648
 
623
649
        new_fname = maildir_generate_tmp_filename(&ioloop_timeval);
624
650
        new_path = t_strconcat(mbox->path, "/new/", new_fname, NULL);
625
651
 
724
750
                                break;
725
751
 
726
752
                        /* possibly duplicate - try fixing it */
727
 
                        if (maildir_fix_duplicate(ctx->mbox,
728
 
                                                  dir, dp->d_name) < 0) {
 
753
                        if (maildir_fix_duplicate(ctx, dir, dp->d_name) < 0) {
729
754
                                ret = -1;
730
755
                                break;
731
756
                        }