dovecot-2.2-pigeonhole: doveadm-sieve: Implemented obtaining las...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Thu Mar 28 22:28:01 EET 2013


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/c6e283350b5d
changeset: 1729:c6e283350b5d
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Thu Mar 28 21:27:53 2013 +0100
description:
doveadm-sieve: Implemented obtaining last modification time for the active script attribute.
It compiles, doesn't break normal ManageSieve operation, but it remains untested otherwise.

diffstat:

 src/lib-sievestorage/sieve-storage-private.h     |   2 +
 src/lib-sievestorage/sieve-storage-script.c      |  26 +++++++++++++++++++++++-
 src/lib-sievestorage/sieve-storage-script.h      |   2 +
 src/lib-sievestorage/sieve-storage.c             |  16 ++++++++++++++
 src/plugins/doveadm-sieve/doveadm-sieve-plugin.c |   5 +++-
 5 files changed, 49 insertions(+), 2 deletions(-)

diffs (125 lines):

diff -r 097764f6bbe3 -r c6e283350b5d src/lib-sievestorage/sieve-storage-private.h
--- a/src/lib-sievestorage/sieve-storage-private.h	Mon Mar 25 12:34:13 2013 +0100
+++ b/src/lib-sievestorage/sieve-storage-private.h	Thu Mar 28 21:27:53 2013 +0100
@@ -63,5 +63,7 @@
 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 097764f6bbe3 -r c6e283350b5d src/lib-sievestorage/sieve-storage-script.c
--- a/src/lib-sievestorage/sieve-storage-script.c	Mon Mar 25 12:34:13 2013 +0100
+++ b/src/lib-sievestorage/sieve-storage-script.c	Thu Mar 28 21:27:53 2013 +0100
@@ -406,10 +406,12 @@
 			sieve_storage_set_critical(storage, "sieve_storage_deactivate(): "
 				"error on unlink(%s): %m", storage->active_path);
 			return -1;
-		} else
+		} else {
 			return 0;
+		}
 	}
 
+	sieve_storage_mark_modified(storage);
 	return 1;
 }
 
@@ -528,6 +530,7 @@
 		}
 	}
 
+	sieve_storage_mark_modified(storage);
 	return activated;
 }
 
@@ -542,6 +545,27 @@
 	return ret;
 }
 
+int sieve_storage_get_active_script_last_change
+(struct sieve_storage *storage, time_t *last_change_r)
+{
+	struct stat st;
+
+	/* Try direct lstat first */
+	if (lstat(storage->active_path, &st) == 0) {
+		*last_change_r = st.st_mtime;
+		return 0;
+	}
+
+	/* Check error */
+	if (errno != ENOENT) {
+		sieve_storage_set_critical(storage, "lstat(%s) failed: %m",
+			   storage->active_path);
+	}
+
+	/* Fall back to statting storage directory */
+	return sieve_storage_get_last_change(storage, last_change_r);
+}
+
 int sieve_storage_script_rename
 (struct sieve_script *script, const char *newname)
 {
diff -r 097764f6bbe3 -r c6e283350b5d src/lib-sievestorage/sieve-storage-script.h
--- a/src/lib-sievestorage/sieve-storage-script.h	Mon Mar 25 12:34:13 2013 +0100
+++ b/src/lib-sievestorage/sieve-storage-script.h	Thu Mar 28 21:27:53 2013 +0100
@@ -18,6 +18,8 @@
 
 struct sieve_script *sieve_storage_get_active_script
 	(struct sieve_storage *storage);
+int sieve_storage_get_active_script_last_change
+	(struct sieve_storage *storage, time_t *last_change_r);
 
 int sieve_storage_script_is_active(struct sieve_script *script);
 
diff -r 097764f6bbe3 -r c6e283350b5d src/lib-sievestorage/sieve-storage.c
--- a/src/lib-sievestorage/sieve-storage.c	Mon Mar 25 12:34:13 2013 +0100
+++ b/src/lib-sievestorage/sieve-storage.c	Thu Mar 28 21:27:53 2013 +0100
@@ -22,6 +22,7 @@
 #include <sys/stat.h>
 #include <ctype.h>
 #include <time.h>
+#include <utime.h>
 
 #define SIEVE_DEFAULT_PATH "~/.dovecot."SIEVE_SCRIPT_FILEEXT
 
@@ -586,6 +587,21 @@
 	return storage->error != NULL ? storage->error : "Unknown error";
 }
 
+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)
 {
diff -r 097764f6bbe3 -r c6e283350b5d src/plugins/doveadm-sieve/doveadm-sieve-plugin.c
--- a/src/plugins/doveadm-sieve/doveadm-sieve-plugin.c	Mon Mar 25 12:34:13 2013 +0100
+++ b/src/plugins/doveadm-sieve/doveadm-sieve-plugin.c	Thu Mar 28 21:27:53 2013 +0100
@@ -268,8 +268,11 @@
 {
 	int ret;
 
-	/* FIXME: set value_r->last_change */
 	ret = sieve_storage_get_active_scriptname(sstorage, &value_r->value);
+	if (ret >= 0) {
+		ret = sieve_storage_get_active_script_last_change
+			(sstorage, &value_r->last_change);
+	}
 	if (ret < 0)
 		mail_storage_set_internal_error(storage);
 	return ret;


More information about the dovecot-cvs mailing list