Mercurial > dovecot > core-2.2
changeset 14082:09db0f7aa6ce
dbox: Never rename() mail files over existing files. If such a file exists, rebuild indexes.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 09 Feb 2012 01:00:14 +0200 |
parents | 41bd2d4c013d |
children | 21c3ce1b21cd |
files | src/lib-storage/index/dbox-multi/mdbox-file.c src/lib-storage/index/dbox-single/sdbox-file.c |
diffstat | 2 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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",
--- 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",