diff src/lib-storage/index/dbox-single/sdbox-file.c @ 14009:10320252b521

sdbox: Preserve file's atime/mtime when moving it to alt storage.
author Timo Sirainen <tss@iki.fi>
date Fri, 27 Jan 2012 15:44:06 +0200
parents 957060ca5b69
children 09db0f7aa6ce
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-single/sdbox-file.c	Fri Jan 27 14:46:38 2012 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-file.c	Fri Jan 27 15:44:06 2012 +0200
@@ -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 @@
 	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 @@
 		(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