changeset 21198:bb081fa224e0

sdbox: Don't log an error if stub is added twice 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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 23 Nov 2016 13:25:54 +0200
parents 3da1e36b61af
children f0d25c596756
files 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
diffstat 3 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-single/sdbox-file.c	Wed Nov 23 13:16:19 2016 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-file.c	Wed Nov 23 13:25:54 2016 +0200
@@ -147,7 +147,8 @@
 	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 @@
 	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);
--- a/src/lib-storage/index/dbox-single/sdbox-file.h	Wed Nov 23 13:16:19 2016 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-file.h	Wed Nov 23 13:25:54 2016 +0200
@@ -29,7 +29,8 @@
 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);
--- a/src/lib-storage/index/dbox-single/sdbox-save.c	Wed Nov 23 13:16:19 2016 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-save.c	Wed Nov 23 13:25:54 2016 +0200
@@ -247,7 +247,7 @@
 
 		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 @@
 				      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;
 	}