]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox: When fixing a broken dbox file, keep a copy of the original broken file.
authorTimo Sirainen <tss@iki.fi>
Mon, 13 Apr 2009 16:52:46 +0000 (12:52 -0400)
committerTimo Sirainen <tss@iki.fi>
Mon, 13 Apr 2009 16:52:46 +0000 (12:52 -0400)
--HG--
branch : HEAD

src/lib-storage/index/dbox/dbox-file-fix.c
src/lib-storage/index/dbox/dbox-storage.h

index 864a3ce24b7d41959a44db767bfa8a7da89895dd..cfb0cca19dcfa33d1ebad7cc2e96f2810b2ad55f 100644 (file)
@@ -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",
index 332f818227bdfc3e213c7290d1dfe39b5acc662d..c3c45edb8336a978bde5cd30dae51d78c22b877e 100644 (file)
@@ -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) */