dovecot-2.0: lib-index: When creating dovecot.index.backup files...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Aug 23 23:25:26 EEST 2011
details: http://hg.dovecot.org/dovecot-2.0/rev/f08bf97278ac
changeset: 12886:f08bf97278ac
user: Timo Sirainen <tss at iki.fi>
date: Tue Aug 23 23:25:14 2011 +0300
description:
lib-index: When creating dovecot.index.backup files, fdatasync() them first.
Otherwise if the dovecot.index file had been written to recently, it could
lose both the new and the old backup data.
diffstat:
src/lib-index/mail-index-write.c | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diffs (20 lines):
diff -r de0ea56932e5 -r f08bf97278ac src/lib-index/mail-index-write.c
--- a/src/lib-index/mail-index-write.c Tue Aug 23 23:03:41 2011 +0300
+++ b/src/lib-index/mail-index-write.c Tue Aug 23 23:25:14 2011 +0300
@@ -18,6 +18,16 @@
const char *backup_path, *tmp_backup_path;
int ret;
+ if (index->fd != -1) {
+ /* we very much want to avoid creating a backup file that
+ hasn't been written to disk yet */
+ if (fdatasync(index->fd) < 0) {
+ mail_index_set_error(index, "fdatasync(%s) failed: %m",
+ tmp_backup_path);
+ return -1;
+ }
+ }
+
backup_path = t_strconcat(index->filepath, ".backup", NULL);
tmp_backup_path = t_strconcat(backup_path, ".tmp", NULL);
ret = link(index->filepath, tmp_backup_path);
More information about the dovecot-cvs
mailing list