]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
sdbox: Preserve file's atime/mtime when moving it to alt storage.
authorTimo Sirainen <tss@iki.fi>
Fri, 27 Jan 2012 13:44:06 +0000 (15:44 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 27 Jan 2012 13:44:06 +0000 (15:44 +0200)
src/lib-storage/index/dbox-single/sdbox-file.c

index 9d585ad62ad1ad46ec8690fc0f1084cbb82f5228..ac9e6fec5d392118c908a8284975e33d31199a5e 100644 (file)
@@ -13,6 +13,7 @@
 #include "sdbox-file.h"
 
 #include <stdio.h>
+#include <utime.h>
 
 static void sdbox_file_init_paths(struct sdbox_file *file, const char *fname)
 {
@@ -271,6 +272,7 @@ int sdbox_file_move(struct dbox_file *file, bool alt_path)
        struct ostream *output;
        const char *dest_dir, *temp_path, *dest_path, *p;
        struct stat st;
+       struct utimbuf ut;
        bool deleted;
        int out_fd, ret = 0;
 
@@ -335,6 +337,14 @@ int sdbox_file_move(struct dbox_file *file, bool alt_path)
                (void)unlink(temp_path);
                return -1;
        }
+       /* preserve the original atime/mtime. this isn't necessary for Dovecot,
+          but could be useful for external reasons. */
+       ut.actime = st.st_atime;
+       ut.modtime = st.st_mtime;
+       if (utime(temp_path, &ut) < 0) {
+               mail_storage_set_critical(storage,
+                       "utime(%s) failed: %m", temp_path);
+       }
 
        /* the temp file was successfully written. rename it now to the
           destination file. the destination shouldn't exist, but if it does