]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
sdbox: Don't log an error if stub is added twice
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 23 Nov 2016 11:25:54 +0000 (13:25 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 23 Nov 2016 12:39:48 +0000 (14:39 +0200)
There's no locking for them, so it's fine if two processes add the same
mail. The second one could be ignored, but it was a bit easier to just
let it rename over the first one.

src/lib-storage/index/dbox-single/sdbox-file.c
src/lib-storage/index/dbox-single/sdbox-file.h
src/lib-storage/index/dbox-single/sdbox-save.c

index 8c7d7a5632c8d39fc5debf1cf9b3a2f0544df257..5c212480e078ff1938a1b1e4078fd81259c4923c 100644 (file)
@@ -147,7 +147,8 @@ static int sdbox_file_rename_attachments(struct sdbox_file *file)
        return ret;
 }
 
-int sdbox_file_assign_uid(struct sdbox_file *file, uint32_t uid)
+int sdbox_file_assign_uid(struct sdbox_file *file, uint32_t uid,
+                         bool ignore_if_exists)
 {
        const char *p, *old_path, *dir, *new_fname, *new_path;
        struct stat st;
@@ -163,7 +164,7 @@ int sdbox_file_assign_uid(struct sdbox_file *file, uint32_t uid)
        new_fname = t_strdup_printf(SDBOX_MAIL_FILE_FORMAT, uid);
        new_path = t_strdup_printf("%s/%s", dir, new_fname);
 
-       if (stat(new_path, &st) == 0) {
+       if (!ignore_if_exists && stat(new_path, &st) == 0) {
                mail_storage_set_critical(&file->file.storage->storage,
                        "sdbox: %s already exists, rebuilding index", new_path);
                sdbox_set_mailbox_corrupted(&file->mbox->box);
index 4d26a45066d73a51b23d28c305c6b37f4aae1069..84b6e53be0ab33f6a0e35c683e7cdd265742c12c 100644 (file)
@@ -29,7 +29,8 @@ const char *
 sdbox_file_attachment_relpath(struct sdbox_file *file, const char *srcpath);
 
 /* Assign UID for a newly created file (by renaming it) */
-int sdbox_file_assign_uid(struct sdbox_file *file, uint32_t uid);
+int sdbox_file_assign_uid(struct sdbox_file *file, uint32_t uid,
+                         bool ignore_if_exists);
 
 int sdbox_file_create_fd(struct dbox_file *file, const char *path,
                         bool parents);
index 57973650668d5742d70c1396c90732da34d0604a..93ec908b97e13e6b1b28469e3c5183f72ca429ca 100644 (file)
@@ -247,7 +247,7 @@ static int dbox_save_assign_uids(struct sdbox_save_context *ctx,
 
                ret = seq_range_array_iter_nth(&iter, n++, &uid);
                i_assert(ret);
-               if (sdbox_file_assign_uid(sfile, uid) < 0)
+               if (sdbox_file_assign_uid(sfile, uid, FALSE) < 0)
                        return -1;
                if (ctx->ctx.highest_pop3_uidl_seq == i+1) {
                        index_pop3_uidl_set_max_uid(&ctx->mbox->box,
@@ -272,7 +272,7 @@ static int dbox_save_assign_stub_uids(struct sdbox_save_context *ctx)
                                      ctx->first_saved_seq + i, &uid);
                i_assert(uid != 0);
 
-               if (sdbox_file_assign_uid(sfile, uid) < 0)
+               if (sdbox_file_assign_uid(sfile, uid, TRUE) < 0)
                        return -1;
        }