]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added mail_index_unlink().
authorTimo Sirainen <tss@iki.fi>
Sun, 17 May 2009 21:54:01 +0000 (17:54 -0400)
committerTimo Sirainen <tss@iki.fi>
Sun, 17 May 2009 21:54:01 +0000 (17:54 -0400)
--HG--
branch : HEAD

src/lib-index/mail-index.c
src/lib-index/mail-index.h
src/lib-index/mail-transaction-log-private.h
src/lib-index/mail-transaction-log.h

index 2ba6d94265059e5ef2facd32e74a3e709489d95d..ee7e90d46865f135e3654ede477344ba1e7b8e95 100644 (file)
@@ -485,6 +485,41 @@ void mail_index_close(struct mail_index *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;
index 8281616936f37d290b211dca18a1513f712b4e84..03f80739a503266ba35ebc78c5d07b1676d62b69 100644 (file)
@@ -205,6 +205,8 @@ int mail_index_open_or_create(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);
index a50f7c92bee03a616879d71c88eae88887b8607b..46c1fc5b8c35ddfa200bc6bded533bca99af4b47 100644 (file)
@@ -4,8 +4,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. */
 #define MAIL_TRANSCATION_LOG_LOCK_TIMEOUT (3*60)
index 2a44cd43c45497e9bda114e1b7741434892c4d30..3abb9d112662b9bbee10cd12a33fd0b16ea625de 100644 (file)
@@ -4,6 +4,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
 #define MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE 24