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