dovecot-1.3: dbox: When fixing a broken dbox file, keep a copy o...

dovecot at dovecot.org dovecot at dovecot.org
Mon Apr 13 19:52:52 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.3/rev/a19365f30de7
changeset: 9086:a19365f30de7
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Apr 13 12:52:46 2009 -0400
description:
dbox: When fixing a broken dbox file, keep a copy of the original broken file.

diffstat:

2 files changed, 14 insertions(+), 1 deletion(-)
src/lib-storage/index/dbox/dbox-file-fix.c |   14 +++++++++++++-
src/lib-storage/index/dbox/dbox-storage.h  |    1 +

diffs (42 lines):

diff -r 1c3ca4aa62b2 -r a19365f30de7 src/lib-storage/index/dbox/dbox-file-fix.c
--- a/src/lib-storage/index/dbox/dbox-file-fix.c	Mon Apr 13 12:40:26 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-file-fix.c	Mon Apr 13 12:52:46 2009 -0400
@@ -290,7 +290,7 @@ int dbox_file_fix(struct dbox_file *file
 int dbox_file_fix(struct dbox_file *file, uoff_t start_offset)
 {
 	struct ostream *output;
-	const char *temp_path;
+	const char *temp_path, *broken_path;
 	char *temp_fname;
 	bool deleted;
 	int fd, ret;
@@ -321,6 +321,18 @@ int dbox_file_fix(struct dbox_file *file
 		}
 		return -1;
 	}
+	/* keep a copy of the original file in case someone wants to look
+	   at it */
+	broken_path = t_strconcat(file->current_path,
+				  DBOX_MAIL_FILE_BROKEN_COPY_SUFFIX, NULL);
+	if (link(file->current_path, broken_path) < 0) {
+		mail_storage_set_critical(&file->storage->storage,
+					  "link(%s, %s) failed: %m",
+					  file->current_path, broken_path);
+	} else {
+		i_warning("dbox: Copy of the broken file saved to %s",
+			  broken_path);
+	}
 	if (rename(temp_path, file->current_path) < 0) {
 		mail_storage_set_critical(&file->storage->storage,
 					  "rename(%s, %s) failed: %m",
diff -r 1c3ca4aa62b2 -r a19365f30de7 src/lib-storage/index/dbox/dbox-storage.h
--- a/src/lib-storage/index/dbox/dbox-storage.h	Mon Apr 13 12:40:26 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-storage.h	Mon Apr 13 12:52:46 2009 -0400
@@ -19,6 +19,7 @@
 #define DBOX_MAIL_FILE_UID_PREFIX "u."
 #define DBOX_MAIL_FILE_MULTI_FORMAT DBOX_MAIL_FILE_MULTI_PREFIX"%u"
 #define DBOX_MAIL_FILE_UID_FORMAT DBOX_MAIL_FILE_UID_PREFIX"%u"
+#define DBOX_MAIL_FILE_BROKEN_COPY_SUFFIX ".broken"
 #define DBOX_GUID_BIN_LEN (128/8)
 
 /* How often to scan for stale temp files (based on dir's atime) */


More information about the dovecot-cvs mailing list