dovecot-2.2-pigeonhole: doveadm-sieve: Set mtime of modified scr...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Sat Apr 20 22:27:28 EEST 2013


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/94cd5a1c85cf
changeset: 1757:94cd5a1c85cf
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Sat Apr 20 21:27:15 2013 +0200
description:
doveadm-sieve: Set mtime of modified scripts and sieve dir to timestamp from dsync.
Still does not fix the ping-pong issue.

diffstat:

 src/lib-sievestorage/sieve-storage-save.c        |  33 ++++++++++++++-
 src/lib-sievestorage/sieve-storage-save.h        |   5 +-
 src/lib-sievestorage/sieve-storage.c             |  53 +++++++++++++++++------
 src/lib-sievestorage/sieve-storage.h             |   2 +
 src/plugins/doveadm-sieve/doveadm-sieve-plugin.c |   7 ++-
 5 files changed, 81 insertions(+), 19 deletions(-)

diffs (226 lines):

diff -r 2de5c020cc03 -r 94cd5a1c85cf src/lib-sievestorage/sieve-storage-save.c
--- a/src/lib-sievestorage/sieve-storage-save.c	Fri Apr 19 23:21:35 2013 +0200
+++ b/src/lib-sievestorage/sieve-storage-save.c	Sat Apr 20 21:27:15 2013 +0200
@@ -37,6 +37,8 @@
 	int fd;
 	const char *tmp_path;
 
+	time_t mtime;
+
 	unsigned int failed:1;
 	unsigned int moving:1;
 	unsigned int finished:1;
@@ -205,6 +207,7 @@
 	ctx->storage = storage;
 	ctx->scriptname = p_strdup(pool, scriptname);
 	ctx->scriptobject = NULL;
+	ctx->mtime = (time_t)-1;
 
 	T_BEGIN {
 		ctx->fd = sieve_storage_create_tmp(storage, scriptname, &path);
@@ -279,6 +282,12 @@
 	return ( ctx->failed ? -1 : 0 );
 }
 
+void sieve_storage_save_set_mtime
+(struct sieve_save_context *ctx, time_t mtime)
+{
+	ctx->mtime = mtime;
+}
+
 static void sieve_storage_save_destroy(struct sieve_save_context **ctx)
 {
 	if ((*ctx)->scriptobject != NULL)
@@ -335,6 +344,23 @@
 	return result;
 }
 
+static void sieve_storage_update_mtime(const char *path, time_t mtime)
+{
+	struct utimbuf times = { .actime = mtime, .modtime = mtime };
+
+	if ( utime(path, &times) < 0 ) {
+		switch ( errno ) {	
+		case ENOENT:
+			break;
+		case EACCES:
+			i_error("sieve-storage: %s", eacces_error_get("utime", path));
+			break;
+		default:
+			i_error("sieve-storage: utime(%s) failed: %m", path);
+		}
+	}
+}
+
 int sieve_storage_save_commit(struct sieve_save_context **ctx)
 {
 	const char *dest_path;
@@ -351,6 +377,9 @@
 		failed = !sieve_storage_script_move((*ctx), dest_path);
 	} T_END;
 
+	if ( (*ctx)->mtime != (time_t)-1 )
+		sieve_storage_update_mtime(dest_path, (*ctx)->mtime);
+
 	sieve_storage_save_destroy(ctx);
 
 	return ( failed ? -1 : 0 );
@@ -371,7 +400,7 @@
 }
 
 int sieve_storage_save_as_active_script(struct sieve_storage *storage,
-	struct istream *input)
+	struct istream *input, time_t mtime)
 {
 	int fd;
 	string_t *temp_path;
@@ -417,7 +446,7 @@
 				"rename(%s, %s) failed: %m", str_c(temp_path), storage->active_path);
 		}
 	} else {
-		sieve_storage_mark_modified(storage);
+		sieve_storage_update_mtime(storage->active_path, mtime);
 	}
 
 	(void)unlink(str_c(temp_path));
diff -r 2de5c020cc03 -r 94cd5a1c85cf src/lib-sievestorage/sieve-storage-save.h
--- a/src/lib-sievestorage/sieve-storage-save.h	Fri Apr 19 23:21:35 2013 +0200
+++ b/src/lib-sievestorage/sieve-storage-save.h	Sat Apr 20 21:27:15 2013 +0200
@@ -22,6 +22,9 @@
 bool sieve_storage_save_will_activate
 	(struct sieve_save_context *ctx);
 
+void sieve_storage_save_set_mtime
+	(struct sieve_save_context *ctx, time_t mtime);
+
 void sieve_storage_save_cancel(struct sieve_save_context **ctx);
 
 int sieve_storage_save_commit(struct sieve_save_context **ctx);
@@ -30,7 +33,7 @@
  * This is needed for the doveadm-sieve plugin.
  */
 int sieve_storage_save_as_active_script(struct sieve_storage *storage,
-	struct istream *input);
+	struct istream *input, time_t mtime);
 
 #endif
 
diff -r 2de5c020cc03 -r 94cd5a1c85cf src/lib-sievestorage/sieve-storage.c
--- a/src/lib-sievestorage/sieve-storage.c	Fri Apr 19 23:21:35 2013 +0200
+++ b/src/lib-sievestorage/sieve-storage.c	Sat Apr 20 21:27:15 2013 +0200
@@ -483,21 +483,6 @@
 	pool_unref(&storage->pool);
 }
 
-void sieve_storage_mark_modified(struct sieve_storage *storage)
-{
-	if ( utime(storage->dir, NULL) < 0 ) {
-		switch ( errno ) {
-		case ENOENT:
-			break;
-		case EACCES:
-			i_error("sieve-storage: %s", eacces_error_get("utime", storage->dir));
-			break;
-		default:
-			i_error("sieve-storage: utime(%s) failed: %m", storage->dir);
-		}
-	}
-}
-
 int sieve_storage_get_last_change
 (struct sieve_storage *storage, time_t *last_change_r)
 {
@@ -516,6 +501,44 @@
 	return 0;
 }
 
+void sieve_storage_set_modified
+(struct sieve_storage *storage, time_t mtime)
+{
+	struct utimbuf times = { .actime = mtime, .modtime = mtime };
+	time_t cur_mtime;
+
+	if ( sieve_storage_get_last_change(storage, &cur_mtime) >= 0 &&
+		cur_mtime > mtime )
+		return;
+	
+	if ( utime(storage->dir, &times) < 0 ) {
+		switch ( errno ) {
+		case ENOENT:
+			break;
+		case EACCES:
+			i_error("sieve-storage: %s", eacces_error_get("utime", storage->dir));
+			break;
+		default:
+			i_error("sieve-storage: utime(%s) failed: %m", storage->dir);
+		}
+	}
+}
+
+void sieve_storage_mark_modified(struct sieve_storage *storage)
+{
+	if ( utime(storage->dir, NULL) < 0 ) {
+		switch ( errno ) {
+		case ENOENT:
+			break;
+		case EACCES:
+			i_error("sieve-storage: %s", eacces_error_get("utime", storage->dir));
+			break;
+		default:
+			i_error("sieve-storage: utime(%s) failed: %m", storage->dir);
+		}
+	}
+}
+
 /* Error handling */
 
 struct sieve_error_handler *sieve_storage_get_error_handler
diff -r 2de5c020cc03 -r 94cd5a1c85cf src/lib-sievestorage/sieve-storage.h
--- a/src/lib-sievestorage/sieve-storage.h	Fri Apr 19 23:21:35 2013 +0200
+++ b/src/lib-sievestorage/sieve-storage.h	Sat Apr 20 21:27:15 2013 +0200
@@ -40,5 +40,7 @@
 
 int sieve_storage_get_last_change
 	(struct sieve_storage *storage, time_t *last_change_r);
+void sieve_storage_set_modified
+	(struct sieve_storage *storage, time_t mtime);
 
 #endif
diff -r 2de5c020cc03 -r 94cd5a1c85cf src/plugins/doveadm-sieve/doveadm-sieve-plugin.c
--- a/src/plugins/doveadm-sieve/doveadm-sieve-plugin.c	Fri Apr 19 23:21:35 2013 +0200
+++ b/src/plugins/doveadm-sieve/doveadm-sieve-plugin.c	Sat Apr 20 21:27:15 2013 +0200
@@ -184,6 +184,7 @@
 	}
 	if (script != NULL)
 		sieve_script_unref(&script);
+	sieve_storage_set_modified(svstorage, value->last_change);
 	return ret;
 }
 
@@ -224,7 +225,8 @@
 		return sieve_attribute_unset_active_script(storage, svstorage);
 	}
 
-	if (sieve_storage_save_as_active_script(svstorage, input) < 0) {
+	if (sieve_storage_save_as_active_script
+		(svstorage, input, value->last_change) < 0) {
 		mail_storage_set_critical(storage,
 			"Failed to save active sieve script: %s",
 			sieve_storage_get_last_error(svstorage, NULL));
@@ -232,6 +234,7 @@
 		return -1;
 	}
 
+	sieve_storage_set_modified(svstorage, value->last_change);
 	i_stream_unref(&input);
 	return 0;
 }
@@ -274,6 +277,8 @@
 		return sieve_attribute_unset_script(storage, svstorage, scriptname);
 	}
 
+	sieve_storage_save_set_mtime(save_ctx, value->last_change);
+
 	if (save_ctx == NULL) {
 		/* save initialization failed */
 		mail_storage_set_critical(storage,


More information about the dovecot-cvs mailing list