[PATCH 4/9] lib: Make notmuch_database_get_directory return NULL if the directory...
authorAustin Clements <amdragon@MIT.EDU>
Fri, 18 May 2012 04:13:37 +0000 (00:13 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:12 +0000 (09:47 -0800)
b6/73ec3ca3c2da2b7e6a29542dd1b1b4f3931ed5 [new file with mode: 0644]

diff --git a/b6/73ec3ca3c2da2b7e6a29542dd1b1b4f3931ed5 b/b6/73ec3ca3c2da2b7e6a29542dd1b1b4f3931ed5
new file mode 100644 (file)
index 0000000..adb3012
--- /dev/null
@@ -0,0 +1,153 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id C59B1429E36\r
+       for <notmuch@notmuchmail.org>; Thu, 17 May 2012 21:13:57 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id f6FsxONCc4Gh for <notmuch@notmuchmail.org>;\r
+       Thu, 17 May 2012 21:13:56 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
+       [18.9.25.15])\r
+       by olra.theworths.org (Postfix) with ESMTP id 3BABA431E62\r
+       for <notmuch@notmuchmail.org>; Thu, 17 May 2012 21:13:53 -0700 (PDT)\r
+X-AuditID: 1209190f-b7f4f6d00000092b-3e-4fb5cc809aa4\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 18.3A.02347.08CC5BF4; Fri, 18 May 2012 00:13:52 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q4I4DpsS001785; \r
+       Fri, 18 May 2012 00:13:51 -0400\r
+Received: from drake.mit.edu\r
+       (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [209.6.116.242]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q4I4Doal026787\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Fri, 18 May 2012 00:13:51 -0400 (EDT)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1SVEZa-0000z6-Ed; Fri, 18 May 2012 00:13:50 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/9] lib: Make notmuch_database_get_directory return NULL if\r
+       the directory is not found\r
+Date: Fri, 18 May 2012 00:13:37 -0400\r
+Message-Id: <1337314423-3702-5-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1337314423-3702-1-git-send-email-amdragon@mit.edu>\r
+References: <1337314423-3702-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsUixCmqrdtwZqu/wbp76hbXb85kdmD0eLbq\r
+       FnMAYxSXTUpqTmZZapG+XQJXxrk7KQUfJSvO7etlaWDsF+1i5OSQEDCRaOhpYYawxSQu3FvP\r
+       1sXIxSEksI9R4tT5FiYIZwOjxM6Nm5ghnPtMEguvfoUqm8Uose/nWhaQfjYBDYlt+5czgtgi\r
+       AtISO+/OZu1i5OBgFlCT+NOlAhIWFkiX+HpjIiNImEVAVeJWtzVImFfAXuLkww4WiCvkJZ7e\r
+       72MDKeEUcJCYdjwaJCwEVPLvQjPLBEb+BYwMqxhlU3KrdHMTM3OKU5N1i5MT8/JSi3RN9HIz\r
+       S/RSU0o3MYIDRpJ/B+O3g0qHGAU4GJV4eHfM2eovxJpYVlyZe4hRkoNJSZT3+0mgEF9Sfkpl\r
+       RmJxRnxRaU5q8SFGCQ5mJRFe2W6gHG9KYmVValE+TEqag0VJnFdN652fkEB6YklqdmpqQWoR\r
+       TFaGg0NJgtfiNFCjYFFqempFWmZOCUKaiYMTZDgP0HAtkBre4oLE3OLMdIj8KUZFKXFeG5CE\r
+       AEgiozQPrhcW0a8YxYFeEeYNBaniASYDuO5XQIOZgAaX5W4CGVySiJCSamBsuBLUJW3CUP1k\r
+       2YwXCWsnGqzu23f/4tmur0cO8LYuYPbI138+eRbnxhfFb5WDDr8/L/FPhF/X6OGHvJ1154xj\r
+       Zq1kf9V8ZN9R7okaqhezd0yZE/upuuuL2i5xwbz+fG3x/TdiIi/1Ol1k6vyuPrvTblVOI0/O\r
+       q52M3wr1lwsG5jwttxLKvfBKiaU4I9FQi7moOBEAuD00AcMCAAA=\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\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: Fri, 18 May 2012 04:13:58 -0000\r
+\r
+Using the new support from _notmuch_directory_create, this makes\r
+notmuch_database_get_directory a read-only operation that simply\r
+returns the directory object if it exists or NULL otherwise.  This\r
+also means that notmuch_database_get_directory can work on read-only\r
+databases.\r
+\r
+This change breaks the directory mtime workaround in notmuch-new.c by\r
+fixing the exact issue it was working around.  This permits mtime\r
+update races to prevent scans of changed directories, which\r
+non-deterministically breaks a few tests.  The next patch fixes this.\r
+---\r
+ lib/database.cc       |    7 ++-----\r
+ lib/notmuch-private.h |    3 +++\r
+ lib/notmuch.h         |   10 ++--------\r
+ 3 files changed, 7 insertions(+), 13 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index b4c76b4..e27a0e1 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -1328,12 +1328,9 @@ notmuch_database_get_directory (notmuch_database_t *notmuch,\r
+       return NOTMUCH_STATUS_NULL_POINTER;\r
+     *directory = NULL;\r
+ \r
+-    /* XXX Handle read-only databases properly */\r
+-    if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)\r
+-      return NOTMUCH_STATUS_READ_ONLY_DATABASE;\r
+-\r
+     try {\r
+-      *directory = _notmuch_directory_create (notmuch, path, NOTMUCH_FIND_CREATE, &status);\r
++      *directory = _notmuch_directory_create (notmuch, path,\r
++                                              NOTMUCH_FIND_LOOKUP, &status);\r
+     } catch (const Xapian::Error &error) {\r
+       fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",\r
+                error.get_msg().c_str());\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index 34f7ac7..bfb4111 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -148,6 +148,9 @@ typedef enum _notmuch_private_status {\r
+ \r
+ /* Flags shared by various lookup functions. */\r
+ typedef enum _notmuch_find_flags {\r
++    /* Lookup without creating any documents.  This is the default\r
++     * behavior. */\r
++    NOTMUCH_FIND_LOOKUP = 0,\r
+     /* If set, create the necessary document (or documents) if they\r
+      * are missing.  Requires a read/write database. */\r
+     NOTMUCH_FIND_CREATE = 1<<0,\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index bbb17e4..3633bed 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -300,10 +300,8 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch);\r
+  * (see notmuch_database_get_path), or else should be an absolute path\r
+  * with initial components that match the path of 'database'.\r
+  *\r
+- * Note: Currently this will create the directory object if it doesn't\r
+- * exist.  In the future, when a directory object does not exist this\r
+- * will return NOTMUCH_STATUS_SUCCESS and set *directory to NULL.\r
+- * Callers should be prepared for this.\r
++ * If this directory object does not exist in the database, this\r
++ * returns NOTMUCH_STATUS_SUCCESS and sets *directory to NULL.\r
+  *\r
+  * Return value:\r
+  *\r
+@@ -313,10 +311,6 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch);\r
+  *\r
+  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;\r
+  *    directory not retrieved.\r
+- *\r
+- * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
+- *    mode so the directory cannot be created (this case will be\r
+- *    removed in the future).\r
+  */\r
+ notmuch_status_t\r
+ notmuch_database_get_directory (notmuch_database_t *database,\r
+-- \r
+1.7.10\r
+\r