dovecot-2.0: sdbox: Preserve file's atime/mtime when moving it t...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jan 27 15:44:30 EET 2012
details: http://hg.dovecot.org/dovecot-2.0/rev/5eb5c9b9d88b
changeset: 13029:5eb5c9b9d88b
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 ac8b3da5dd07 -r 5eb5c9b9d88b src/lib-storage/index/dbox-single/sdbox-file.c
--- a/src/lib-storage/index/dbox-single/sdbox-file.c Fri Jan 27 14:35: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)
{
@@ -270,6 +271,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;
@@ -334,6 +336,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