summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJani Nikula <jani@nikula.org>2015-09-25 23:48:45 +0300
committerDavid Bremner <david@tethera.net>2015-10-10 09:14:25 -0300
commit727fcd18c6a3897622582e71a2d71081e3ae40ea (patch)
tree0544aba2ee3f34d4b86d350d4a04c3774d73dd70
parent0e03ff389443aa062d30e6949bb3220563c474be (diff)
lib: add interface to delete directory documents
As mentioned in acd66cdec075312944e527febd46382e54d99367 we don't have an interface to delete directory documents, and they're left behind. Add the interface.
-rw-r--r--lib/directory.cc25
-rw-r--r--lib/notmuch.h10
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/directory.cc b/lib/directory.cc
index b836ea28..78637b3a 100644
--- a/lib/directory.cc
+++ b/lib/directory.cc
@@ -281,6 +281,31 @@ notmuch_directory_get_child_directories (notmuch_directory_t *directory)
return child_directories;
}
+notmuch_status_t
+notmuch_directory_delete (notmuch_directory_t *directory)
+{
+ notmuch_status_t status;
+ Xapian::WritableDatabase *db;
+
+ status = _notmuch_database_ensure_writable (directory->notmuch);
+ if (status)
+ return status;
+
+ try {
+ db = static_cast <Xapian::WritableDatabase *> (directory->notmuch->xapian_db);
+ db->delete_document (directory->document_id);
+ } catch (const Xapian::Error &error) {
+ _notmuch_database_log (directory->notmuch,
+ "A Xapian exception occurred deleting directory entry: %s.\n",
+ error.get_msg().c_str());
+ directory->notmuch->exception_reported = TRUE;
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+ }
+ notmuch_directory_destroy (directory);
+
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
void
notmuch_directory_destroy (notmuch_directory_t *directory)
{
diff --git a/lib/notmuch.h b/lib/notmuch.h
index c5f7dcb4..85b56bf1 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1762,6 +1762,16 @@ notmuch_filenames_t *
notmuch_directory_get_child_directories (notmuch_directory_t *directory);
/**
+ * Delete directory document from the database, and destroy the
+ * notmuch_directory_t object. Assumes any child directories and files
+ * have been deleted by the caller.
+ *
+ * @since libnotmuch 4.3 (notmuch 0.21)
+ */
+notmuch_status_t
+notmuch_directory_delete (notmuch_directory_t *directory);
+
+/**
* Destroy a notmuch_directory_t object.
*/
void