Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id F03FE6DE143A for ; Sat, 10 Oct 2015 05:30:19 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.105 X-Spam-Level: X-Spam-Status: No, score=0.105 tagged_above=-999 required=5 tests=[AWL=0.105] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KBw1UOLjUz_S for ; Sat, 10 Oct 2015 05:30:18 -0700 (PDT) Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224]) by arlo.cworth.org (Postfix) with ESMTPS id 17B976DE140C for ; Sat, 10 Oct 2015 05:30:18 -0700 (PDT) Received: from remotemail by gitolite.debian.net with local (Exim 4.80) (envelope-from ) id 1ZktGX-0008B3-Ts; Sat, 10 Oct 2015 12:28:45 +0000 Received: (nullmailer pid 8596 invoked by uid 1000); Sat, 10 Oct 2015 12:27:30 -0000 From: David Bremner To: Jani Nikula , notmuch@notmuchmail.org Subject: [PATCH 2/3] lib: add interface to delete directory documents Date: Sat, 10 Oct 2015 09:27:18 -0300 Message-Id: <1444480039-8530-3-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.5.3 In-Reply-To: <1444480039-8530-1-git-send-email-david@tethera.net> References: <591f5298ac3f2c79f727cac8bad1251830b28a3c.1443213654.git.jani@nikula.org> <1444480039-8530-1-git-send-email-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Oct 2015 12:30:20 -0000 From: Jani Nikula 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 (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