dovecot-1.2: Added mail_index_unlink().

dovecot at dovecot.org dovecot at dovecot.org
Mon May 18 00:55:07 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/c8d63b42e9cc
changeset: 9041:c8d63b42e9cc
user:      Timo Sirainen <tss at iki.fi>
date:      Sun May 17 17:54:01 2009 -0400
description:
Added mail_index_unlink().

diffstat:

4 files changed, 39 insertions(+), 2 deletions(-)
src/lib-index/mail-index.c                   |   35 ++++++++++++++++++++++++++
src/lib-index/mail-index.h                   |    2 +
src/lib-index/mail-transaction-log-private.h |    2 -
src/lib-index/mail-transaction-log.h         |    2 +

diffs (81 lines):

diff -r 533e4829212a -r c8d63b42e9cc src/lib-index/mail-index.c
--- a/src/lib-index/mail-index.c	Sun May 17 17:30:58 2009 -0400
+++ b/src/lib-index/mail-index.c	Sun May 17 17:54:01 2009 -0400
@@ -470,6 +470,41 @@ void mail_index_close(struct mail_index 
 	index->opened = FALSE;
 }
 
+int mail_index_unlink(struct mail_index *index)
+{
+	const char *path;
+	int last_errno = 0;
+
+	if (MAIL_INDEX_IS_IN_MEMORY(index))
+		return 0;
+
+	/* main index */
+	if (unlink(index->filepath) < 0 && errno != ENOENT)
+		last_errno = errno;
+
+	/* logs */
+	path = t_strconcat(index->filepath, MAIL_TRANSACTION_LOG_SUFFIX, NULL);
+	if (unlink(path) < 0 && errno != ENOENT)
+		last_errno = errno;
+
+	path = t_strconcat(index->filepath,
+			   MAIL_TRANSACTION_LOG_SUFFIX".2", NULL);
+	if (unlink(path) < 0 && errno != ENOENT)
+		last_errno = errno;
+
+	/* cache */
+	path = t_strconcat(index->filepath, MAIL_CACHE_FILE_SUFFIX, NULL);
+	if (unlink(path) < 0 && errno != ENOENT)
+		last_errno = errno;
+
+	if (last_errno == 0)
+		return 0;
+	else {
+		errno = last_errno;
+		return -1;
+	}
+}
+
 int mail_index_reopen_if_changed(struct mail_index *index)
 {
 	struct stat st1, st2;
diff -r 533e4829212a -r c8d63b42e9cc src/lib-index/mail-index.h
--- a/src/lib-index/mail-index.h	Sun May 17 17:30:58 2009 -0400
+++ b/src/lib-index/mail-index.h	Sun May 17 17:54:01 2009 -0400
@@ -190,6 +190,8 @@ int mail_index_open(struct mail_index *i
 int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
 		    enum file_lock_method lock_method);
 void mail_index_close(struct mail_index *index);
+/* unlink() all the index files. */
+int mail_index_unlink(struct mail_index *index);
 
 /* Returns TRUE if index is currently in memory. */
 bool mail_index_is_in_memory(struct mail_index *index);
diff -r 533e4829212a -r c8d63b42e9cc src/lib-index/mail-transaction-log-private.h
--- a/src/lib-index/mail-transaction-log-private.h	Sun May 17 17:30:58 2009 -0400
+++ b/src/lib-index/mail-transaction-log-private.h	Sun May 17 17:54:01 2009 -0400
@@ -3,8 +3,6 @@
 
 #include "file-dotlock.h"
 #include "mail-transaction-log.h"
-
-#define MAIL_TRANSACTION_LOG_SUFFIX ".log"
 
 /* Synchronization can take a while sometimes, especially when copying lots of
    mails. */
diff -r 533e4829212a -r c8d63b42e9cc src/lib-index/mail-transaction-log.h
--- a/src/lib-index/mail-transaction-log.h	Sun May 17 17:30:58 2009 -0400
+++ b/src/lib-index/mail-transaction-log.h	Sun May 17 17:54:01 2009 -0400
@@ -3,6 +3,8 @@
 
 struct mail_index;
 struct mail_index_transaction;
+
+#define MAIL_TRANSACTION_LOG_SUFFIX ".log"
 
 #define MAIL_TRANSACTION_LOG_MAJOR_VERSION 1
 #define MAIL_TRANSACTION_LOG_MINOR_VERSION 2


More information about the dovecot-cvs mailing list