[PATCH 2/3] lib: add interface to delete directory documents

David Bremner david at tethera.net
Sat Oct 10 05:27:18 PDT 2015


From: Jani Nikula <jani at nikula.org>

As mentioned in acd66cdec075312944e527febd46382e54d99367 we don't have
an interface to delete directory documents, and they're left behind. Add
the interface.
---
 lib/directory.cc | 25 +++++++++++++++++++++++++
 lib/notmuch.h    | 10 ++++++++++
 2 files changed, 35 insertions(+)

diff --git a/lib/directory.cc b/lib/directory.cc
index b836ea2..78637b3 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 c5f7dcb..85b56bf 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
-- 
2.5.3



More information about the notmuch mailing list