--- /dev/null
+Return-Path: <amthrax@drake.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 376E3429E47\r
+ for <notmuch@notmuchmail.org>; Mon, 30 Apr 2012 09:25:48 -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 T1DyEDjCiaEJ for <notmuch@notmuchmail.org>;\r
+ Mon, 30 Apr 2012 09:25:47 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
+ [18.7.68.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 60925429E3E\r
+ for <notmuch@notmuchmail.org>; Mon, 30 Apr 2012 09:25:45 -0700 (PDT)\r
+X-AuditID: 12074422-b7fd66d0000008f9-91-4f9ebd0805e6\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 44.AF.02297.80DBE9F4; Mon, 30 Apr 2012 12:25:44 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q3UGPhSm001281; \r
+ Mon, 30 Apr 2012 12:25:43 -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 q3UGPgXS005256\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Mon, 30 Apr 2012 12:25:43 -0400 (EDT)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
+ (envelope-from <amthrax@drake.mit.edu>)\r
+ id 1SOtPx-0006H7-KB; Mon, 30 Apr 2012 12:25:41 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 2/6] lib/cli: Make notmuch_database_create return a status\r
+ code\r
+Date: Mon, 30 Apr 2012 12:25:34 -0400\r
+Message-Id: <1335803138-24024-3-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1335803138-24024-1-git-send-email-amdragon@mit.edu>\r
+References: <1335651473-19652-1-git-send-email-amdragon@mit.edu>\r
+ <1335803138-24024-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixG6nrsuxd56/wZwFOhbXb85kdmD0eLbq\r
+ FnMAYxSXTUpqTmZZapG+XQJXxs51R1kLfitWtHWfZW1g/CTVxcjJISFgIvF4dy8rhC0mceHe\r
+ erYuRi4OIYF9jBJr2t9AORsYJdoP/mGFcO4zSVz+dA3Kmc8o8alzCjtIP5uAhsS2/csZQWwR\r
+ AWmJnXdnAxVxcDALqEn86VIBCQsLBEl8PPoIrIRFQFVi1vWVTCA2r4CDxM7LbewQZyhIPFt3\r
+ HCzOKeAocevANxYQW0igXGLjhU+MExj5FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdI11cvN\r
+ LNFLTSndxAgOGxelHYw/DyodYhTgYFTi4X2xcJ6/EGtiWXFl7iFGSQ4mJVFe3T1AIb6k/JTK\r
+ jMTijPii0pzU4kOMEhzMSiK8pROBcrwpiZVVqUX5MClpDhYlcV51rXd+QgLpiSWp2ampBalF\r
+ MFkZDg4lCV57kKGCRanpqRVpmTklCGkmDk6Q4TxAw8FqeIsLEnOLM9Mh8qcYFaXEeRNBEgIg\r
+ iYzSPLheWFy/YhQHekWYNxCkigeYEuC6XwENZgIanG8ONrgkESEl1cBoGJe+9l6awI0WiXTu\r
+ cudfyismSEQ/NkvWPRuZW3Zyiaq579Ztb/uvsBnlXm1iCgrZ5Vb4ev/NOkn1hXONnRhUGLtO\r
+ K15btjc83J5znWUsZ8Pb16c6wnltHT45l766+uQvb+WWG+/veO8IUi5hCWj1MYw6e0qWmSX7\r
+ +fOml2ozRCLUROJieJRYijMSDbWYi4oTAYrH6Y/GAgAA\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: Mon, 30 Apr 2012 16:25:48 -0000\r
+\r
+This is the notmuch_database_create equivalent of the previous change.\r
+\r
+In this case, there were places where errors were not being propagated\r
+correctly in notmuch_database_create or in calls to it. These have\r
+been fixed, using the new status value.\r
+---\r
+ lib/database.cc | 29 ++++++++++++++++++++++-------\r
+ lib/notmuch.h | 22 ++++++++++++++++++----\r
+ notmuch-new.c | 3 ++-\r
+ 3 files changed, 42 insertions(+), 12 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 1e66599..07f186e 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -520,9 +520,10 @@ parse_references (void *ctx,\r
+ }\r
+ }\r
+ \r
+-notmuch_database_t *\r
+-notmuch_database_create (const char *path)\r
++notmuch_status_t\r
++notmuch_database_create (const char *path, notmuch_database_t **database)\r
+ {\r
++ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
+ notmuch_database_t *notmuch = NULL;\r
+ char *notmuch_path = NULL;\r
+ struct stat st;\r
+@@ -530,6 +531,7 @@ notmuch_database_create (const char *path)\r
+ \r
+ if (path == NULL) {\r
+ fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");\r
++ status = NOTMUCH_STATUS_NULL_POINTER;\r
+ goto DONE;\r
+ }\r
+ \r
+@@ -537,12 +539,14 @@ notmuch_database_create (const char *path)\r
+ if (err) {\r
+ fprintf (stderr, "Error: Cannot create database at %s: %s.\n",\r
+ path, strerror (errno));\r
++ status = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+ }\r
+ \r
+ if (! S_ISDIR (st.st_mode)) {\r
+ fprintf (stderr, "Error: Cannot create database at %s: Not a directory.\n",\r
+ path);\r
++ status = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+ }\r
+ \r
+@@ -553,19 +557,30 @@ notmuch_database_create (const char *path)\r
+ if (err) {\r
+ fprintf (stderr, "Error: Cannot create directory %s: %s.\n",\r
+ notmuch_path, strerror (errno));\r
++ status = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+ }\r
+ \r
+- notmuch_database_open (path,\r
+- NOTMUCH_DATABASE_MODE_READ_WRITE,\r
+- ¬much);\r
+- notmuch_database_upgrade (notmuch, NULL, NULL);\r
++ status = notmuch_database_open (path,\r
++ NOTMUCH_DATABASE_MODE_READ_WRITE,\r
++ ¬much);\r
++ if (status)\r
++ goto DONE;\r
++ status = notmuch_database_upgrade (notmuch, NULL, NULL);\r
++ if (status) {\r
++ notmuch_database_close(notmuch);\r
++ notmuch = NULL;\r
++ }\r
+ \r
+ DONE:\r
+ if (notmuch_path)\r
+ talloc_free (notmuch_path);\r
+ \r
+- return notmuch;\r
++ if (database)\r
++ *database = notmuch;\r
++ else\r
++ talloc_free (notmuch);\r
++ return status;\r
+ }\r
+ \r
+ notmuch_status_t\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 44b0c46..e6e5cc2 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -140,11 +140,25 @@ typedef struct _notmuch_filenames notmuch_filenames_t;\r
+ * contained within 'path' can be added to the database by calling\r
+ * notmuch_database_add_message.\r
+ *\r
+- * In case of any failure, this function returns NULL, (after printing\r
+- * an error message on stderr).\r
++ * In case of any failure, this function returns an error status and\r
++ * sets *database to NULL (after printing an error message on stderr).\r
++ *\r
++ * Return value:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: Successfully created the database.\r
++ *\r
++ * NOTMUCH_STATUS_NULL_POINTER: The given 'path' argument is NULL.\r
++ *\r
++ * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.\r
++ *\r
++ * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to create the\r
++ * database file (such as permission denied, or file not found,\r
++ * etc.), or the database already exists.\r
++ *\r
++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.\r
+ */\r
+-notmuch_database_t *\r
+-notmuch_database_create (const char *path);\r
++notmuch_status_t\r
++notmuch_database_create (const char *path, notmuch_database_t **database);\r
+ \r
+ typedef enum {\r
+ NOTMUCH_DATABASE_MODE_READ_ONLY = 0,\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 7788743..cb720cc 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -900,7 +900,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+ return 1;\r
+ \r
+ printf ("Found %d total files (that's not much mail).\n", count);\r
+- notmuch = notmuch_database_create (db_path);\r
++ if (notmuch_database_create (db_path, ¬much))\r
++ return 1;\r
+ add_files_state.total_files = count;\r
+ } else {\r
+ if (notmuch_database_open (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE,\r
+-- \r
+1.7.9.1\r
+\r