Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id DA802431FB6 for ; Sat, 28 Apr 2012 15:18:03 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JLiq5t7m1cK9 for ; Sat, 28 Apr 2012 15:18:01 -0700 (PDT) Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU [18.9.25.12]) by olra.theworths.org (Postfix) with ESMTP id 008FD431FC2 for ; Sat, 28 Apr 2012 15:17:59 -0700 (PDT) X-AuditID: 1209190c-b7fad6d000000920-ae-4f9c6c97ab96 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id 20.19.02336.79C6C9F4; Sat, 28 Apr 2012 18:17:59 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q3SMHwFx005266; Sat, 28 Apr 2012 18:17:58 -0400 Received: from drake.mit.edu (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3SMHvfi008918 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 28 Apr 2012 18:17:58 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1SOFxk-00058D-UF; Sat, 28 Apr 2012 18:17:57 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 1/6] lib/cli: Make notmuch_database_open return a status code Date: Sat, 28 Apr 2012 18:17:48 -0400 Message-Id: <1335651473-19652-2-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1335651473-19652-1-git-send-email-amdragon@mit.edu> References: <1335651473-19652-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrTs9Z46/wbwGRYvrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoEro+uvT8E974rD+w6xNTAutuli5OSQEDCReHj6CDOELSZx4d56 ti5GLg4hgX2MEvvb37JDOBsYJe6v/Abl3GeS6N2+kxGkRUhgPqPE3gfuIDabgIbEtv3LweIi AtISO+/OZu1i5OBgFlCT+NOlAhIWFvCV6L/dwwpiswioSjRdX88CYvMKOEjs7rrPCnGFgsSz dceZQGxOAUeJ/5tPsEOscpDomDeBbQIj/wJGhlWMsim5Vbq5iZk5xanJusXJiXl5qUW6hnq5 mSV6qSmlmxjBISPJs4PxzUGlQ4wCHIxKPLwH18/yF2JNLCuuzD3EKMnBpCTKy5I1x1+ILyk/ pTIjsTgjvqg0J7X4EKMEB7OSCK+2OFCONyWxsiq1KB8mJc3BoiTOq6L1zk9IID2xJDU7NbUg tQgmK8PBoSTB25oN1ChYlJqeWpGWmVOCkGbi4AQZzgM0fA9IDW9xQWJucWY6RP4Uo6KUOO96 kIQASCKjNA+uFxbTrxjFgV4R5p0OUsUDTAdw3a+ABjMBDWbynAUyuCQRISXVwDjhWIxX4R/T fPUDRdyXtfv3/ZeuT1ffU1+0nPeKsPXsmsNftnVGHFn0VeAxf8Td+Yu/xPNY9Srv51byXjnd 9OLbouS92xsC+lbcUVi++/8M9Z+X3/zJ6YkIOGS9US7DK1FLRCVkoxy7qGJA2dIPprZJGbfX 1alsXMKqu6dW6m+CaHyFRNkWaSWW4oxEQy3mouJEADajNlLEAgAA X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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, 28 Apr 2012 22:18:04 -0000 It has been a long-standing issue that notmuch_database_open doesn't return any indication of why it failed. This patch changes its prototype to return a notmuch_status_t and set an out-argument to the database itself, like other functions that return both a status and an object. In the interest of atomicity, this also updates every use in the CLI so that notmuch still compiles. Since this patch does not update the bindings, the Python bindings test fails. --- lib/database.cc | 19 ++++++++++++++----- lib/notmuch.h | 12 +++++------- notmuch-count.c | 5 ++--- notmuch-dump.c | 5 ++--- notmuch-new.c | 5 ++--- notmuch-reply.c | 5 ++--- notmuch-restore.c | 5 ++--- notmuch-search.c | 5 ++--- notmuch-show.c | 5 ++--- notmuch-tag.c | 5 ++--- test/symbol-test.cc | 3 ++- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 2fefcad..a29fe67 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -556,8 +556,9 @@ notmuch_database_create (const char *path) goto DONE; } - notmuch = notmuch_database_open (path, - NOTMUCH_DATABASE_MODE_READ_WRITE); + notmuch_database_open (path, + NOTMUCH_DATABASE_MODE_READ_WRITE, + ¬much); notmuch_database_upgrade (notmuch, NULL, NULL); DONE: @@ -578,10 +579,12 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch) return NOTMUCH_STATUS_SUCCESS; } -notmuch_database_t * +notmuch_status_t notmuch_database_open (const char *path, - notmuch_database_mode_t mode) + notmuch_database_mode_t mode, + notmuch_database_t **database) { + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; void *local = talloc_new (NULL); notmuch_database_t *notmuch = NULL; char *notmuch_path, *xapian_path; @@ -592,6 +595,7 @@ notmuch_database_open (const char *path, if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) { fprintf (stderr, "Out of memory\n"); + status = NOTMUCH_STATUS_OUT_OF_MEMORY; goto DONE; } @@ -599,11 +603,13 @@ notmuch_database_open (const char *path, if (err) { fprintf (stderr, "Error opening database at %s: %s\n", notmuch_path, strerror (errno)); + status = NOTMUCH_STATUS_FILE_ERROR; goto DONE; } if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) { fprintf (stderr, "Out of memory\n"); + status = NOTMUCH_STATUS_OUT_OF_MEMORY; goto DONE; } @@ -644,6 +650,7 @@ notmuch_database_open (const char *path, notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY; notmuch_database_destroy (notmuch); notmuch = NULL; + status = NOTMUCH_STATUS_FILE_ERROR; goto DONE; } @@ -704,12 +711,14 @@ notmuch_database_open (const char *path, error.get_msg().c_str()); notmuch_database_destroy (notmuch); notmuch = NULL; + status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; } DONE: talloc_free (local); - return notmuch; + *database = notmuch; + return status; } void diff --git a/lib/notmuch.h b/lib/notmuch.h index 7d9e092..8a011f2 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -151,9 +151,6 @@ typedef enum { NOTMUCH_DATABASE_MODE_READ_WRITE } notmuch_database_mode_t; -/* XXX: I think I'd like this to take an extra argument of - * notmuch_status_t* for returning a status value on failure. */ - /* Open an existing notmuch database located at 'path'. * * The database should have been created at some time in the past, @@ -168,12 +165,13 @@ typedef enum { * The caller should call notmuch_database_destroy when finished with * this database. * - * In case of any failure, this function returns NULL, (after printing - * an error message on stderr). + * In case of any failure, this function returns an error status and + * sets *database to NULL (after printing an error message on stderr). */ -notmuch_database_t * +notmuch_status_t notmuch_database_open (const char *path, - notmuch_database_mode_t mode); + notmuch_database_mode_t mode, + notmuch_database_t **database); /* Close the given notmuch database. * diff --git a/notmuch-count.c b/notmuch-count.c index 9c2ad7b..2f98128 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -66,9 +66,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) if (config == NULL) return 1; - notmuch = notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_ONLY); - if (notmuch == NULL) + if (notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) return 1; query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index); diff --git a/notmuch-dump.c b/notmuch-dump.c index 71ab0ea..3743214 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -36,9 +36,8 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) if (config == NULL) return 1; - notmuch = notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_ONLY); - if (notmuch == NULL) + if (notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) return 1; char *output_file_name = NULL; diff --git a/notmuch-new.c b/notmuch-new.c index 3ff6304..7788743 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -903,9 +903,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) notmuch = notmuch_database_create (db_path); add_files_state.total_files = count; } else { - notmuch = notmuch_database_open (db_path, - NOTMUCH_DATABASE_MODE_READ_WRITE); - if (notmuch == NULL) + if (notmuch_database_open (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE, + ¬much)) return 1; if (notmuch_database_needs_upgrade (notmuch)) { diff --git a/notmuch-reply.c b/notmuch-reply.c index da99a13..7184a5d 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -740,9 +740,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) return 1; } - notmuch = notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_ONLY); - if (notmuch == NULL) + if (notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) return 1; query = notmuch_query_create (notmuch, query_string); diff --git a/notmuch-restore.c b/notmuch-restore.c index 02b563c..4f4096e 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -115,9 +115,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) if (config == NULL) return 1; - notmuch = notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_WRITE); - if (notmuch == NULL) + if (notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) return 1; synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); diff --git a/notmuch-search.c b/notmuch-search.c index 7dfd270..3be296d 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -486,9 +486,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) if (config == NULL) return 1; - notmuch = notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_ONLY); - if (notmuch == NULL) + if (notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) return 1; query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index); diff --git a/notmuch-show.c b/notmuch-show.c index 3b6667c..95427d4 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -1081,9 +1081,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) return 1; } - notmuch = notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_ONLY); - if (notmuch == NULL) + if (notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) return 1; query = notmuch_query_create (notmuch, query_string); diff --git a/notmuch-tag.c b/notmuch-tag.c index bd56fd1..7d18639 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -229,9 +229,8 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) if (config == NULL) return 1; - notmuch = notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_WRITE); - if (notmuch == NULL) + if (notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) return 1; synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); diff --git a/test/symbol-test.cc b/test/symbol-test.cc index 1548ca4..3e96c03 100644 --- a/test/symbol-test.cc +++ b/test/symbol-test.cc @@ -4,7 +4,8 @@ int main() { - (void) notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY); + notmuch_database_t *notmuch; + notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much); try { (void) new Xapian::WritableDatabase("./nonexistant", Xapian::DB_OPEN); -- 1.7.9.1