dovecot-2.1: sdbox: Preserve file's atime/mtime when moving it t...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jan 27 15:44:11 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/10320252b521
changeset: 14009:10320252b521
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jan 27 15:44:06 2012 +0200
description:
sdbox: Preserve file's atime/mtime when moving it to alt storage.

diffstat:

 src/lib-storage/index/dbox-single/sdbox-file.c |  10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diffs (34 lines):

diff -r 6e6c20ab1ed1 -r 10320252b521 src/lib-storage/index/dbox-single/sdbox-file.c
--- 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


More information about the dovecot-cvs mailing list