dovecot-2.2-pigeonhole: doveadm-sieve: Fixed mtime updates.

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Tue Apr 23 23:55:09 EEST 2013


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/5892c2ab9b0d
changeset: 1758:5892c2ab9b0d
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Tue Apr 23 22:55:03 2013 +0200
description:
doveadm-sieve: Fixed mtime updates.
Patch by Timo Sirainen.

diffstat:

 src/lib-sievestorage/sieve-storage-private.h     |   3 +-
 src/lib-sievestorage/sieve-storage-save.c        |   5 +-
 src/lib-sievestorage/sieve-storage-script.c      |  23 ++++-----
 src/lib-sievestorage/sieve-storage-script.h      |   4 +-
 src/lib-sievestorage/sieve-storage.c             |  53 +++++++++--------------
 src/managesieve/cmd-setactive.c                  |   4 +-
 src/plugins/doveadm-sieve/doveadm-sieve-plugin.c |  10 ++--
 7 files changed, 44 insertions(+), 58 deletions(-)

diffs (291 lines):

diff -r 94cd5a1c85cf -r 5892c2ab9b0d src/lib-sievestorage/sieve-storage-private.h
--- a/src/lib-sievestorage/sieve-storage-private.h	Sat Apr 20 21:27:15 2013 +0200
+++ b/src/lib-sievestorage/sieve-storage-private.h	Tue Apr 23 22:55:03 2013 +0200
@@ -49,12 +49,11 @@
 	struct sieve_error_handler *ehandler;
 
 	enum sieve_storage_flags flags;
+	time_t prev_mtime;
 };
 
 struct sieve_script *sieve_storage_script_init_from_path
 	(struct sieve_storage *storage, const char *path, const char *scriptname);
 
-void sieve_storage_mark_modified(struct sieve_storage *storage);
-
 #endif
 
diff -r 94cd5a1c85cf -r 5892c2ab9b0d src/lib-sievestorage/sieve-storage-save.c
--- a/src/lib-sievestorage/sieve-storage-save.c	Sat Apr 20 21:27:15 2013 +0200
+++ b/src/lib-sievestorage/sieve-storage-save.c	Tue Apr 23 22:55:03 2013 +0200
@@ -375,11 +375,10 @@
 			sieve_scriptfile_from_name((*ctx)->scriptname), NULL);
 
 		failed = !sieve_storage_script_move((*ctx), dest_path);
+		if ( (*ctx)->mtime != (time_t)-1 )
+			sieve_storage_update_mtime(dest_path, (*ctx)->mtime);
 	} 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 );
diff -r 94cd5a1c85cf -r 5892c2ab9b0d src/lib-sievestorage/sieve-storage-script.c
--- a/src/lib-sievestorage/sieve-storage-script.c	Sat Apr 20 21:27:15 2013 +0200
+++ b/src/lib-sievestorage/sieve-storage-script.c	Tue Apr 23 22:55:03 2013 +0200
@@ -302,19 +302,18 @@
 {
 	struct stat st;
 
-#if 0
 	/* Try direct lstat first */
 	if (lstat(storage->active_path, &st) == 0) {
-		*last_change_r = st.st_mtime;
-		return 0;
+		if (!S_ISLNK(st.st_mode)) {
+			*last_change_r = st.st_mtime;
+			return 0;
+		}
 	}
-
 	/* Check error */
-	if (errno != ENOENT) {
+	else if (errno != ENOENT) {
 		sieve_storage_set_critical(storage, "lstat(%s) failed: %m",
 			   storage->active_path);
 	}
-#endif
 
 	/* Fall back to statting storage directory */
 	return sieve_storage_get_last_change(storage, last_change_r);
@@ -450,7 +449,7 @@
 	return FALSE;
 }
 
-int sieve_storage_deactivate(struct sieve_storage *storage)
+int sieve_storage_deactivate(struct sieve_storage *storage, time_t mtime)
 {
 	int ret;
 
@@ -470,7 +469,7 @@
 		}
 	}
 
-	sieve_storage_mark_modified(storage);
+	sieve_storage_set_modified(storage, mtime);
 	return 1;
 }
 
@@ -530,7 +529,7 @@
 	return 1;
 }
 
-static int _sieve_storage_script_activate(struct sieve_script *script)
+static int _sieve_storage_script_activate(struct sieve_script *script, time_t mtime)
 {
 	struct sieve_storage_script *st_script =
 		(struct sieve_storage_script *) script;
@@ -589,16 +588,16 @@
 		}
 	}
 
-	sieve_storage_mark_modified(storage);
+	sieve_storage_set_modified(storage, mtime);
 	return activated;
 }
 
-int sieve_storage_script_activate(struct sieve_script *script)
+int sieve_storage_script_activate(struct sieve_script *script, time_t mtime)
 {
 	int ret;
 
 	T_BEGIN {
-		ret = _sieve_storage_script_activate(script);
+		ret = _sieve_storage_script_activate(script, mtime);
 	} T_END;
 
 	return ret;
diff -r 94cd5a1c85cf -r 5892c2ab9b0d src/lib-sievestorage/sieve-storage-script.h
--- a/src/lib-sievestorage/sieve-storage-script.h	Sat Apr 20 21:27:15 2013 +0200
+++ b/src/lib-sievestorage/sieve-storage-script.h	Tue Apr 23 22:55:03 2013 +0200
@@ -23,9 +23,9 @@
 int sieve_storage_active_script_get_last_change
 	(struct sieve_storage *storage, time_t *last_change_r);
 
-int sieve_storage_deactivate(struct sieve_storage *storage);
+int sieve_storage_deactivate(struct sieve_storage *storage, time_t mtime);
 int sieve_storage_script_is_active(struct sieve_script *script);
-int sieve_storage_script_activate(struct sieve_script *script);
+int sieve_storage_script_activate(struct sieve_script *script, time_t mtime);
 int sieve_storage_script_delete(struct sieve_script **script);
 int sieve_storage_script_rename
 	(struct sieve_script *script, const char *newname);
diff -r 94cd5a1c85cf -r 5892c2ab9b0d src/lib-sievestorage/sieve-storage.c
--- a/src/lib-sievestorage/sieve-storage.c	Sat Apr 20 21:27:15 2013 +0200
+++ b/src/lib-sievestorage/sieve-storage.c	Tue Apr 23 22:55:03 2013 +0200
@@ -381,6 +381,17 @@
 			"using sieve script storage directory: %s", storage_dir);
 	}
 
+	/* get the storage mtime before we modify it ourself. FIXME: do this
+	   later, only just before modifying the sieve dir */
+	struct stat st;
+	if (stat(storage_dir, &st) < 0) {
+		if (errno != ENOENT) {
+			i_error("stat(%s) failed: %m", storage_dir);
+			return NULL;
+		}
+		st.st_mtime = 0;
+	}
+
 	/* Get permissions */
 
 	sieve_storage_get_permissions
@@ -416,6 +427,7 @@
 	storage->user = p_strdup(pool, user);
 	storage->active_path = p_strdup(pool, active_path);
 	storage->active_fname = p_strdup(pool, active_fname);
+	storage->prev_mtime = st.st_mtime;
 
 	storage->dir_create_mode = dir_create_mode;
 	storage->file_create_mode = file_create_mode;
@@ -458,7 +470,6 @@
 				(unsigned long long int) storage->max_scripts);
 		}
 	}
-
 	return storage;
 }
 
@@ -486,18 +497,7 @@
 int sieve_storage_get_last_change
 (struct sieve_storage *storage, time_t *last_change_r)
 {
-	struct stat st;
-
-	if (stat(storage->dir, &st) < 0) {
-		if (errno == ENOENT) {
-			*last_change_r = 0;
-			return 0;
-		}
-		sieve_storage_set_critical(storage, "stat(%s) failed: %m",
-					   storage->dir);
-		return -1;
-	}
-	*last_change_r = st.st_mtime;
+	*last_change_r = storage->prev_mtime;
 	return 0;
 }
 
@@ -507,10 +507,12 @@
 	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 ( mtime != (time_t)-1 ) {
+		if ( sieve_storage_get_last_change(storage, &cur_mtime) >= 0 &&
+			cur_mtime > mtime )
+			return;
+	}
+
 	if ( utime(storage->dir, &times) < 0 ) {
 		switch ( errno ) {
 		case ENOENT:
@@ -521,21 +523,8 @@
 		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);
-		}
+	} else {
+		storage->prev_mtime = mtime;
 	}
 }
 
diff -r 94cd5a1c85cf -r 5892c2ab9b0d src/managesieve/cmd-setactive.c
--- a/src/managesieve/cmd-setactive.c	Sat Apr 20 21:27:15 2013 +0200
+++ b/src/managesieve/cmd-setactive.c	Tue Apr 23 22:55:03 2013 +0200
@@ -68,7 +68,7 @@
 			/* Refresh activation no matter what; this can also resolve some erroneous
 			 * situations.
 			 */
-			ret = sieve_storage_script_activate(script);
+			ret = sieve_storage_script_activate(script, (time_t)-1);
 			if ( ret < 0 ) {
 				client_send_storage_error(client, storage);
 			} else {
@@ -90,7 +90,7 @@
 
 	/* ... deactivate */
 	} else {
-		ret = sieve_storage_deactivate(storage);
+		ret = sieve_storage_deactivate(storage, (time_t)-1);
 
 		if ( ret < 0 )
 			client_send_storage_error(client, storage);
diff -r 94cd5a1c85cf -r 5892c2ab9b0d src/plugins/doveadm-sieve/doveadm-sieve-plugin.c
--- a/src/plugins/doveadm-sieve/doveadm-sieve-plugin.c	Sat Apr 20 21:27:15 2013 +0200
+++ b/src/plugins/doveadm-sieve/doveadm-sieve-plugin.c	Tue Apr 23 22:55:03 2013 +0200
@@ -164,7 +164,7 @@
 		}
 
 		/* deactivate current script */
-		if (sieve_storage_deactivate(svstorage) < 0) {
+		if (sieve_storage_deactivate(svstorage, value->last_change) < 0) {
 			mail_storage_set_critical(storage,
 				"Failed to deactivate Sieve: %s",
 				sieve_storage_get_last_error(svstorage, NULL));
@@ -176,7 +176,7 @@
 	/* activate specified script */
 	script = sieve_storage_script_init(svstorage, scriptname);
 	ret = script == NULL ? -1 :
-		sieve_storage_script_activate(script);
+		sieve_storage_script_activate(script, value->last_change);
 	if (ret < 0) {
 		mail_storage_set_critical(storage,
 			"Failed to activate Sieve script '%s': %s", scriptname,
@@ -190,7 +190,7 @@
 
 static int
 sieve_attribute_unset_active_script(struct mail_storage *storage,
-			   struct sieve_storage *svstorage)
+			   struct sieve_storage *svstorage, time_t last_change)
 {
 	int ret;
 
@@ -200,7 +200,7 @@
 		return ret;
 	}
 
-	if (sieve_storage_deactivate(svstorage) < 0) {
+	if (sieve_storage_deactivate(svstorage, last_change) < 0) {
 		mail_storage_set_critical(storage,
 			"Failed to deactivate sieve: %s",
 			sieve_storage_get_last_error(svstorage, NULL));
@@ -222,7 +222,7 @@
 		input = value->value_stream;
 		i_stream_ref(input);
 	} else {
-		return sieve_attribute_unset_active_script(storage, svstorage);
+		return sieve_attribute_unset_active_script(storage, svstorage, value->last_change);
 	}
 
 	if (sieve_storage_save_as_active_script


More information about the dovecot-cvs mailing list