611
611
(void)maildir_sync_index_finish(&ctx->index_sync_ctx, TRUE);
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)
617
struct maildir_mailbox *mbox = ctx->mbox;
618
const char *existing_fname, *existing_path;
617
619
const char *new_fname, *old_path, *new_path;
624
maildir_uidlist_sync_get_full_filename(ctx->uidlist_sync_ctx,
626
i_assert(existing_fname != NULL);
630
existing_path = t_strconcat(dir, "/", existing_fname, NULL);
622
631
old_path = t_strconcat(dir, "/", old_fname, NULL);
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. */
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
623
649
new_fname = maildir_generate_tmp_filename(&ioloop_timeval);
624
650
new_path = t_strconcat(mbox->path, "/new/", new_fname, NULL);
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) {