From 271ec23b4e9110f02928a647c7a26a3f1deea3bd Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 24 May 2011 21:36:55 +0300 Subject: [PATCH] * mu-util.h, mu-util-db.cc: make mu_util_xapian_clear also clear the contacts-cache --- src/mu-util-db.cc | 18 ++++++++++++++++-- src/mu-util.h | 6 ++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/mu-util-db.cc b/src/mu-util-db.cc index eea2fc82..138f32b2 100644 --- a/src/mu-util-db.cc +++ b/src/mu-util-db.cc @@ -99,16 +99,30 @@ mu_util_xapian_is_empty (const gchar* xpath) } gboolean -mu_util_xapian_clear (const gchar *xpath) +mu_util_xapian_clear (const gchar *xpath, + const char *ccache) { g_return_val_if_fail (xpath, FALSE); + g_return_val_if_fail (ccache, FALSE); try { + int rv; + + /* clear the database */ Xapian::WritableDatabase db (xpath, Xapian::DB_CREATE_OR_OVERWRITE); db.flush (); - MU_WRITE_LOG ("emptied database %s", xpath); + + /* clear the contacts cache; this is not totally + * fail-safe, as some other process may still have it + * open... */ + rv = unlink (ccache); + if (rv != 0 && errno != ENOENT) { + g_warning ("failed to remove contacts-cache: %s", + strerror(errno)); + return FALSE; + } return TRUE; diff --git a/src/mu-util.h b/src/mu-util.h index b3ee9f94..8ce7fd74 100644 --- a/src/mu-util.h +++ b/src/mu-util.h @@ -184,13 +184,15 @@ gboolean mu_util_xapian_is_empty (const gchar *xpath); /** * clear the database, ie., remove all of the contents. This is a * destructive operation, but the database can be restored be doing a - * full scan of the maildirs. + * full scan of the maildirs. Also, clear the contacts cache file * * @param xpath path to the database + * @param ccache path to the contacts cache file * * @return TRUE if the clearing succeeded, FALSE otherwise. */ -gboolean mu_util_xapian_clear (const gchar *xpath); +gboolean mu_util_xapian_clear (const gchar *xpath, + const gchar *ccache); /**