dovecot-2.2: acl: Preserve dovecot-acl file's mtime when dsyncing.

dovecot at dovecot.org dovecot at dovecot.org
Tue Mar 19 14:00:59 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/394e1c6f0aaf
changeset: 16048:394e1c6f0aaf
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Mar 19 14:00:49 2013 +0200
description:
acl: Preserve dovecot-acl file's mtime when dsyncing.

diffstat:

 src/plugins/acl/acl-api.h           |   2 ++
 src/plugins/acl/acl-attributes.c    |   1 +
 src/plugins/acl/acl-backend-vfile.c |  18 ++++++++++++++++++
 3 files changed, 21 insertions(+), 0 deletions(-)

diffs (73 lines):

diff -r 45999b94692c -r 394e1c6f0aaf src/plugins/acl/acl-api.h
--- a/src/plugins/acl/acl-api.h	Tue Mar 19 14:00:21 2013 +0200
+++ b/src/plugins/acl/acl-api.h	Tue Mar 19 14:00:49 2013 +0200
@@ -85,6 +85,8 @@
 
 	enum acl_modify_mode modify_mode;
 	enum acl_modify_mode neg_modify_mode;
+	/* These changes' "last changed" timestamp */
+	time_t last_change;
 };
 
 /* data contains the information needed to initialize ACL backend. If username
diff -r 45999b94692c -r 394e1c6f0aaf src/plugins/acl/acl-attributes.c
--- a/src/plugins/acl/acl-attributes.c	Tue Mar 19 14:00:21 2013 +0200
+++ b/src/plugins/acl/acl-attributes.c	Tue Mar 19 14:00:49 2013 +0200
@@ -38,6 +38,7 @@
 	memset(&update, 0, sizeof(update));
 	update.modify_mode = ACL_MODIFY_MODE_REPLACE;
 	update.neg_modify_mode = ACL_MODIFY_MODE_REPLACE;
+	update.last_change = value->last_change;
 	id = key + strlen(MAILBOX_ATTRIBUTE_PREFIX_ACL);
 	rights = value->value == NULL ? NULL : t_strsplit(value->value, " ");
 	if (acl_rights_update_import(&update, id, rights, &error) < 0) {
diff -r 45999b94692c -r 394e1c6f0aaf src/plugins/acl/acl-backend-vfile.c
--- a/src/plugins/acl/acl-backend-vfile.c	Tue Mar 19 14:00:21 2013 +0200
+++ b/src/plugins/acl/acl-backend-vfile.c	Tue Mar 19 14:00:49 2013 +0200
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <utime.h>
 #include <sys/stat.h>
 
 #define ACL_ESTALE_RETRY_COUNT NFS_ESTALE_RETRY_COUNT
@@ -1136,7 +1137,10 @@
 	struct acl_object_vfile *aclobj = (struct acl_object_vfile *)_aclobj;
 	struct acl_backend_vfile *backend =
 		(struct acl_backend_vfile *)_aclobj->backend;
+	struct acl_backend_vfile_validity *validity;
 	struct dotlock *dotlock;
+	struct utimbuf ut;
+	time_t orig_mtime;
 	const char *path;
 	unsigned int i;
 	int fd;
@@ -1159,6 +1163,10 @@
 		return 0;
 	}
 
+	validity = acl_cache_get_validity(_aclobj->backend->cache,
+					  _aclobj->name);
+	orig_mtime = validity->local_validity.last_mtime;
+
 	/* ACLs were really changed, write the new ones */
 	path = file_dotlock_get_lock_path(dotlock);
 	if (acl_backend_vfile_update_write(aclobj, fd, path) < 0) {
@@ -1166,6 +1174,16 @@
 		acl_cache_flush(_aclobj->backend->cache, _aclobj->name);
 		return -1;
 	}
+	if (orig_mtime < update->last_change && update->last_change != 0) {
+		/* set mtime to last_change, if it's higher than the file's
+		   original mtime. if original mtime is higher, then we're
+		   merging some changes and it's better for the mtime to get
+		   updated. */
+		ut.actime = ioloop_time;
+		ut.modtime = update->last_change;
+		if (utime(path, &ut) < 0)
+			i_error("utime(%s) failed: %m", path);
+	}
 	acl_backend_vfile_update_cache(_aclobj, fd);
 	if (file_dotlock_replace(&dotlock, 0) < 0) {
 		acl_cache_flush(_aclobj->backend->cache, _aclobj->name);


More information about the dovecot-cvs mailing list