dovecot-2.0: lib-index: Added mail_index_get_modification_time().

dovecot at dovecot.org dovecot at dovecot.org
Mon Feb 15 04:31:38 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/31aca1df525b
changeset: 10722:31aca1df525b
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Feb 15 04:29:47 2010 +0200
description:
lib-index: Added mail_index_get_modification_time().

diffstat:

 src/lib-index/mail-index.c           |  17 +++++++++++++++++
 src/lib-index/mail-index.h           |   2 ++
 src/lib-index/mail-transaction-log.c |  18 ++++++++++++++++++
 src/lib-index/mail-transaction-log.h |   4 ++++
 4 files changed, 41 insertions(+), 0 deletions(-)

diffs (77 lines):

diff -r ea8f213f0e19 -r 31aca1df525b src/lib-index/mail-index.c
--- a/src/lib-index/mail-index.c	Mon Feb 15 04:08:46 2010 +0200
+++ b/src/lib-index/mail-index.c	Mon Feb 15 04:29:47 2010 +0200
@@ -751,6 +751,23 @@
 	return index->index_delete_requested || index->index_deleted;
 }
 
+int mail_index_get_modification_time(struct mail_index *index, time_t *mtime_r)
+{
+	struct stat st;
+
+	if (mail_transaction_log_get_mtime(index->log, mtime_r) < 0)
+		return -1;
+
+	if (*mtime_r == 0) {
+		if (stat(index->filepath, &st) < 0) {
+			mail_index_set_syscall_error(index, "stat()");
+			return -1;
+		}
+		*mtime_r = st.st_mtime;
+	}
+	return 0;
+}
+
 void mail_index_fchown(struct mail_index *index, int fd, const char *path)
 {
 	mode_t mode;
diff -r ea8f213f0e19 -r 31aca1df525b src/lib-index/mail-index.h
--- a/src/lib-index/mail-index.h	Mon Feb 15 04:08:46 2010 +0200
+++ b/src/lib-index/mail-index.h	Mon Feb 15 04:29:47 2010 +0200
@@ -456,6 +456,8 @@
 /* Returns TRUE if index has been set deleted. This gets set only after
    index has been opened/refreshed and the transaction has been seen. */
 bool mail_index_is_deleted(struct mail_index *index);
+/* Returns the last time mailbox was modified. */
+int mail_index_get_modification_time(struct mail_index *index, time_t *mtime_r);
 
 /* Lookup a keyword, returns TRUE if found, FALSE if not. */
 bool mail_index_keyword_lookup(struct mail_index *index,
diff -r ea8f213f0e19 -r 31aca1df525b src/lib-index/mail-transaction-log.c
--- a/src/lib-index/mail-transaction-log.c	Mon Feb 15 04:08:46 2010 +0200
+++ b/src/lib-index/mail-transaction-log.c	Mon Feb 15 04:29:47 2010 +0200
@@ -509,3 +509,21 @@
 	return log->head->hdr.prev_file_seq == file_seq &&
 		log->head->hdr.prev_file_offset == file_offset;
 }
+
+int mail_transaction_log_get_mtime(struct mail_transaction_log *log,
+				   time_t *mtime_r)
+{
+	struct stat st;
+
+	*mtime_r = 0;
+	if (stat(log->filepath, &st) < 0) {
+		if (errno == ENOENT)
+			return 0;
+
+		mail_index_file_set_syscall_error(log->index, log->filepath,
+						  "stat()");
+		return -1;
+	}
+	*mtime_r = st.st_mtime;
+	return 0;
+}
diff -r ea8f213f0e19 -r 31aca1df525b src/lib-index/mail-transaction-log.h
--- a/src/lib-index/mail-transaction-log.h	Mon Feb 15 04:08:46 2010 +0200
+++ b/src/lib-index/mail-transaction-log.h	Mon Feb 15 04:29:47 2010 +0200
@@ -280,5 +280,9 @@
 /* Move currently opened log head file to memory (called by
    mail_index_move_to_memory()) */
 void mail_transaction_log_move_to_memory(struct mail_transaction_log *log);
+/* Returns mtime of the transaction log head file.
+   If it doesn't exist, mtime_r is set to 0. */
+int mail_transaction_log_get_mtime(struct mail_transaction_log *log,
+				   time_t *mtime_r);
 
 #endif


More information about the dovecot-cvs mailing list