From: Timo Sirainen Date: Mon, 13 Apr 2009 16:52:46 +0000 (-0400) Subject: dbox: When fixing a broken dbox file, keep a copy of the original broken file. X-Git-Tag: 2.0.alpha1~966 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=16fc1f7ccba286bea35fcc2a40693fa0b571fe4b;p=thirdparty%2Fdovecot%2Fcore.git dbox: When fixing a broken dbox file, keep a copy of the original broken file. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/dbox/dbox-file-fix.c b/src/lib-storage/index/dbox/dbox-file-fix.c index 864a3ce24b..cfb0cca19d 100644 --- a/src/lib-storage/index/dbox/dbox-file-fix.c +++ b/src/lib-storage/index/dbox/dbox-file-fix.c @@ -290,7 +290,7 @@ dbox_file_fix_write_stream(struct dbox_file *file, uoff_t start_offset, 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, uoff_t start_offset) } 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 --git a/src/lib-storage/index/dbox/dbox-storage.h b/src/lib-storage/index/dbox/dbox-storage.h index 332f818227..c3c45edb83 100644 --- a/src/lib-storage/index/dbox/dbox-storage.h +++ b/src/lib-storage/index/dbox/dbox-storage.h @@ -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) */