unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/3] lib: add interface to delete directory documents
Date: Fri, 25 Sep 2015 23:48:45 +0300	[thread overview]
Message-ID: <a9303b1bb200dc529b3bdfa35dc8f9f7e603a06f.1443213654.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1443213654.git.jani@nikula.org>
In-Reply-To: <cover.1443213654.git.jani@nikula.org>

As mentioned in

commit acd66cdec075312944e527febd46382e54d99367
Author: Jani Nikula <jani@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

  parent reply	other threads:[~2015-09-25 20:49 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 ` Jani Nikula [this message]
2015-09-28 11:42   ` [PATCH 2/3] lib: add interface to delete directory documents 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     ` [PATCH 2/3] lib: add interface to delete directory documents David Bremner
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=a9303b1bb200dc529b3bdfa35dc8f9f7e603a06f.1443213654.git.jani@nikula.org \
    --to=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).