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

Jani Nikula jani at nikula.org
Fri Sep 25 13:48:45 PDT 2015


As mentioned in

commit acd66cdec075312944e527febd46382e54d99367
Author: Jani Nikula <jani at nikula.org>
Date:   Sat Sep 5 12:35:31 2015 +0300

    cli: reset db directory mtime upon directory removal

we don't have an interface to delete directory documents, and they're
left behind. Add the interface.

XXX: Should this also remove the files under it, or assume that's been
done by the caller? Should this incorporate some or all of the
functionality of _remove_directory() in notmuch-new.c?
---
 lib/directory.cc | 18 ++++++++++++++++++
 lib/notmuch.h    |  7 +++++++
 2 files changed, 25 insertions(+)

diff --git a/lib/directory.cc b/lib/directory.cc
index b836ea2812c8..f23b71769aef 100644
--- a/lib/directory.cc
+++ b/lib/directory.cc
@@ -281,6 +281,24 @@ 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;
+
+    db = static_cast <Xapian::WritableDatabase *> (directory->notmuch->xapian_db);
+    db->delete_document (directory->document_id);
+
+    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 87756838d072..1feda4521e4d 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1720,6 +1720,13 @@ 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.
+ */
+notmuch_status_t
+notmuch_directory_delete (notmuch_directory_t *directory);
+
+/**
  * Destroy a notmuch_directory_t object.
  */
 void
-- 
2.1.4



More information about the notmuch mailing list