--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 038616DE1271\r
+ for <notmuch@notmuchmail.org>; Sat, 10 Oct 2015 05:30:01 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.105\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.105 tagged_above=-999 required=5 tests=[AWL=0.105]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id x2bikh0Zri6b for <notmuch@notmuchmail.org>;\r
+ Sat, 10 Oct 2015 05:29:59 -0700 (PDT)\r
+Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 0E1E26DE1502\r
+ for <notmuch@notmuchmail.org>; Sat, 10 Oct 2015 05:29:59 -0700 (PDT)\r
+Received: from remotemail by gitolite.debian.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1ZktGF-0008Av-01; Sat, 10 Oct 2015 12:28:26 +0000\r
+Received: (nullmailer pid 8598 invoked by uid 1000); Sat, 10 Oct 2015\r
+ 12:27:30 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
+Subject: [PATCH 3/3] cli: delete directory documents on directory removal\r
+Date: Sat, 10 Oct 2015 09:27:19 -0300\r
+Message-Id: <1444480039-8530-4-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.5.3\r
+In-Reply-To: <1444480039-8530-1-git-send-email-david@tethera.net>\r
+References:\r
+ <591f5298ac3f2c79f727cac8bad1251830b28a3c.1443213654.git.jani@nikula.org>\r
+ <1444480039-8530-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 10 Oct 2015 12:30:01 -0000\r
+\r
+From: Jani Nikula <jani@nikula.org>\r
+\r
+There was a problem with the directory documents being left behind when\r
+the filesystem directory was removed. This was worked around in [1].\r
+However, that ignored the fact that the directory documents are also\r
+still listed by notmuch_directory_get_child_directories() leading to\r
+confusing results when running notmuch new. The directory documents are\r
+found and queued for removal over and over again.\r
+\r
+Fix the problem for real by removing the directory documents. This fixes\r
+the tests flagged as broken in [2].\r
+\r
+The (non-deterministic) hack test from [1] also still passes with this\r
+change.\r
+\r
+[1] commit acd66cdec075312944e527febd46382e54d99367\r
+[2] commit ed9ceda623d3f22fb66365b33db63c5c982067d3\r
+[3] id:1441445731-4362-1-git-send-email-jani@nikula.org\r
+---\r
+ notmuch-new.c | 12 +++---------\r
+ test/T050-new.sh | 6 ------\r
+ 2 files changed, 3 insertions(+), 15 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 442a2f0..d45d0af 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -878,17 +878,11 @@ _remove_directory (void *ctx,\r
+ goto DONE;\r
+ }\r
+ \r
+- /*\r
+- * XXX: The library does not have a function to remove a directory\r
+- * document for a path. Usually this doesn't matter except for a\r
+- * slight waste of space. However, if the directory gets added to\r
+- * the filesystem again, the old directory document is found with\r
+- * the old mtime. Reset the directory mtime to avoid problems.\r
+- */\r
+- notmuch_directory_set_mtime (directory, 0);\r
++ status = notmuch_directory_delete (directory);\r
+ \r
+ DONE:\r
+- notmuch_directory_destroy (directory);\r
++ if (status)\r
++ notmuch_directory_destroy (directory);\r
+ return status;\r
+ }\r
+ \r
+diff --git a/test/T050-new.sh b/test/T050-new.sh\r
+index 33ce1ab..81cf2fa 100755\r
+--- a/test/T050-new.sh\r
++++ b/test/T050-new.sh\r
+@@ -93,7 +93,6 @@ No new mail. Detected 3 file renames."\r
+ \r
+ \r
+ test_begin_subtest "Deleted directory"\r
+-test_subtest_known_broken\r
+ rm -rf "${MAIL_DIR}"/dir-renamed\r
+ \r
+ output=$(NOTMUCH_NEW --debug)\r
+@@ -102,7 +101,6 @@ No new mail. Removed 3 messages."\r
+ \r
+ \r
+ test_begin_subtest "New directory (at end of list)"\r
+-test_subtest_known_broken\r
+ \r
+ generate_message [dir]=zzz\r
+ generate_message [dir]=zzz\r
+@@ -114,7 +112,6 @@ test_expect_equal "$output" "Added 3 new messages to the database."\r
+ \r
+ test_begin_subtest "Deleted directory (end of list)"\r
+ \r
+-test_subtest_known_broken\r
+ rm -rf "${MAIL_DIR}"/zzz\r
+ \r
+ output=$(NOTMUCH_NEW --debug)\r
+@@ -173,7 +170,6 @@ test_expect_equal "$output" "(D) add_files_recursive, pass 3: queuing leftover d\r
+ No new mail. Removed 3 messages."\r
+ \r
+ test_begin_subtest "Support single-message mbox"\r
+-test_subtest_known_broken\r
+ cat > "${MAIL_DIR}"/mbox_file1 <<EOF\r
+ From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001\r
+ From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
+@@ -187,7 +183,6 @@ test_expect_equal "$output" "Added 1 new message to the database."\r
+ \r
+ # This test requires that notmuch new has been run at least once.\r
+ test_begin_subtest "Skip and report non-mail files"\r
+-test_subtest_known_broken\r
+ generate_message\r
+ mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config\r
+ touch "${MAIL_DIR}"/ignored_file\r
+@@ -224,7 +219,6 @@ output=$(NOTMUCH_NEW 2>&1)\r
+ test_expect_equal "$output" "Added 1 new message to the database."\r
+ \r
+ test_begin_subtest "Ignore files and directories specified in new.ignore (multiple occurrences)"\r
+-test_subtest_known_broken\r
+ notmuch config set new.ignore .git ignored_file .ignored_hidden_file\r
+ notmuch new > /dev/null # ensure that files/folders will be printed in ASCII order.\r
+ touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.\r
+-- \r
+2.5.3\r
+\r