From 4d4d585520538a752e9f0a4a1c019a2918f52e56 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 17 May 2009 17:54:01 -0400 Subject: [PATCH] Added mail_index_unlink(). --HG-- branch : HEAD --- 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 ++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/lib-index/mail-index.c b/src/lib-index/mail-index.c index 2ba6d94265..ee7e90d468 100644 --- a/src/lib-index/mail-index.c +++ b/src/lib-index/mail-index.c @@ -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; diff --git a/src/lib-index/mail-index.h b/src/lib-index/mail-index.h index 8281616936..03f80739a5 100644 --- a/src/lib-index/mail-index.h +++ b/src/lib-index/mail-index.h @@ -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); diff --git a/src/lib-index/mail-transaction-log-private.h b/src/lib-index/mail-transaction-log-private.h index a50f7c92be..46c1fc5b8c 100644 --- a/src/lib-index/mail-transaction-log-private.h +++ b/src/lib-index/mail-transaction-log-private.h @@ -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) diff --git a/src/lib-index/mail-transaction-log.h b/src/lib-index/mail-transaction-log.h index 2a44cd43c4..3abb9d1126 100644 --- a/src/lib-index/mail-transaction-log.h +++ b/src/lib-index/mail-transaction-log.h @@ -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 -- 2.47.3