From: Jani Nikula Date: Fri, 25 Sep 2015 20:48:45 +0000 (+0300) Subject: lib: add interface to delete directory documents X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=727fcd18c6a3897622582e71a2d71081e3ae40ea;p=notmuch.git 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. --- 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 (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 @@ -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); +/** + * 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. */