lib: add interface to delete directory documents
authorJani Nikula <jani@nikula.org>
Fri, 25 Sep 2015 20:48:45 +0000 (23:48 +0300)
committerDavid Bremner <david@tethera.net>
Sat, 10 Oct 2015 12:14:25 +0000 (09:14 -0300)
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
lib/notmuch.h

index b836ea2812c88e47b5a8f91007eb24f99b3925ae..78637b3ad6236333b9d992ee9d1c7fe87e46f1ad 100644 (file)
@@ -281,6 +281,31 @@ notmuch_directory_get_child_directories (notmuch_directory_t *directory)
     return child_directories;
 }
 
     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)
 {
 void
 notmuch_directory_destroy (notmuch_directory_t *directory)
 {
index c5f7dcb4b9f10f28b4eab46e4844d7f06680fc05..85b56bf1e4c34e96fe37e4df7a06eb4b762f2e75 100644 (file)
@@ -1761,6 +1761,16 @@ notmuch_directory_get_child_files (notmuch_directory_t *directory);
 notmuch_filenames_t *
 notmuch_directory_get_child_directories (notmuch_directory_t *directory);
 
 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.
  */
 /**
  * Destroy a notmuch_directory_t object.
  */