From: Timo Sirainen Date: Fri, 27 Jan 2012 13:44:06 +0000 (+0200) Subject: sdbox: Preserve file's atime/mtime when moving it to alt storage. X-Git-Tag: 2.1.rc6~131 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf77eee4f485c152886e12bc3aa288da81c68532;p=thirdparty%2Fdovecot%2Fcore.git sdbox: Preserve file's atime/mtime when moving it to alt storage. --- diff --git a/src/lib-storage/index/dbox-single/sdbox-file.c b/src/lib-storage/index/dbox-single/sdbox-file.c index 9d585ad62a..ac9e6fec5d 100644 --- a/src/lib-storage/index/dbox-single/sdbox-file.c +++ b/src/lib-storage/index/dbox-single/sdbox-file.c @@ -13,6 +13,7 @@ #include "sdbox-file.h" #include +#include 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