dovecot-2.1: dbox: Never rename() mail files over existing files...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Feb 9 01:00:27 EET 2012
details: http://hg.dovecot.org/dovecot-2.1/rev/09db0f7aa6ce
changeset: 14082:09db0f7aa6ce
user: Timo Sirainen <tss at iki.fi>
date: Thu Feb 09 01:00:14 2012 +0200
description:
dbox: Never rename() mail files over existing files. If such a file exists, rebuild indexes.
diffstat:
src/lib-storage/index/dbox-multi/mdbox-file.c | 8 ++++++++
src/lib-storage/index/dbox-single/sdbox-file.c | 8 ++++++++
2 files changed, 16 insertions(+), 0 deletions(-)
diffs (50 lines):
diff -r 41bd2d4c013d -r 09db0f7aa6ce src/lib-storage/index/dbox-multi/mdbox-file.c
--- a/src/lib-storage/index/dbox-multi/mdbox-file.c Thu Feb 09 00:59:44 2012 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-file.c Thu Feb 09 01:00:14 2012 +0200
@@ -185,6 +185,7 @@
int mdbox_file_assign_file_id(struct mdbox_file *file, uint32_t file_id)
{
+ struct stat st;
const char *old_path;
const char *new_dir, *new_fname, *new_path;
@@ -196,6 +197,13 @@
new_dir = !dbox_file_is_in_alt(&file->file) ?
file->storage->storage_dir : file->storage->alt_storage_dir;
new_path = t_strdup_printf("%s/%s", new_dir, new_fname);
+
+ if (stat(new_path, &st) == 0) {
+ mail_storage_set_critical(&file->file.storage->storage,
+ "mdbox: %s already exists, rebuilding index", new_path);
+ mdbox_storage_set_corrupted(file->storage);
+ return -1;
+ }
if (rename(old_path, new_path) < 0) {
mail_storage_set_critical(&file->storage->storage.storage,
"rename(%s, %s) failed: %m",
diff -r 41bd2d4c013d -r 09db0f7aa6ce src/lib-storage/index/dbox-single/sdbox-file.c
--- a/src/lib-storage/index/dbox-single/sdbox-file.c Thu Feb 09 00:59:44 2012 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-file.c Thu Feb 09 01:00:14 2012 +0200
@@ -146,6 +146,7 @@
int sdbox_file_assign_uid(struct sdbox_file *file, uint32_t uid)
{
const char *old_path, *new_fname, *new_path;
+ struct stat st;
i_assert(file->uid == 0);
i_assert(uid != 0);
@@ -154,6 +155,13 @@
new_fname = t_strdup_printf(SDBOX_MAIL_FILE_FORMAT, uid);
new_path = t_strdup_printf("%s/%s", mailbox_get_path(&file->mbox->box),
new_fname);
+
+ if (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);
+ return -1;
+ }
if (rename(old_path, new_path) < 0) {
mail_storage_set_critical(&file->file.storage->storage,
"rename(%s, %s) failed: %m",
More information about the dovecot-cvs
mailing list