Mercurial > dovecot > core-2.2
diff src/lib-storage/index/dbox-single/sdbox-file.c @ 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 | 10320252b521 |
children | ba770cba5598 |
line wrap: on
line diff
--- 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",