unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org
Subject: [PATCH 2/3] lib: add interface to delete directory documents
Date: Sat, 10 Oct 2015 09:27:18 -0300	[thread overview]
Message-ID: <1444480039-8530-3-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1444480039-8530-1-git-send-email-david@tethera.net>

From: Jani Nikula <jani@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

  parent reply	other threads:[~2015-10-10 12:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-25 20:48 [PATCH 0/3] delete directory documents on directory removal Jani Nikula
2015-09-25 20:48 ` [PATCH 1/3] test: flag one more notmuch new test as broken Jani Nikula
2015-09-25 20:48 ` [PATCH 2/3] lib: add interface to delete directory documents Jani Nikula
2015-09-28 11:42   ` David Bremner
2015-09-25 20:48 ` [PATCH 3/3] cli: delete directory documents on directory removal Jani Nikula
2015-10-10 12:27   ` V2 of directory delete patches David Bremner
2015-10-10 12:27     ` [PATCH 1/3] test: flag one more notmuch new test as broken David Bremner
2015-10-10 12:27     ` David Bremner [this message]
2015-10-10 12:27     ` [PATCH 3/3] cli: delete directory documents on directory removal David Bremner
2015-10-11 16:45     ` V2 of directory delete patches Tomi Ollila
2015-10-14 10:58       ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1444480039-8530-3-git-send-email-david@tethera.net \
    --to=david@tethera.net \
    --cc=jani@nikula.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).