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 DB3CE431FB6 for ; Sat, 28 Apr 2012 15:18:00 -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 KBC305-39tM6 for ; Sat, 28 Apr 2012 15:17:59 -0700 (PDT) Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU [18.9.25.13]) by olra.theworths.org (Postfix) with ESMTP id A4EEA431FAF for ; Sat, 28 Apr 2012 15:17:59 -0700 (PDT) X-AuditID: 1209190d-b7fbf6d0000008ba-5f-4f9c6c9790fe Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP id BB.B8.02234.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-1.mit.edu (8.13.8/8.9.2) with ESMTP id q3SMHw6Q029824; 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 q3SMHvw1008919 (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 1SOFxl-00058G-3R; Sat, 28 Apr 2012 18:17:57 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 2/6] lib/cli: Make notmuch_database_create return a status code Date: Sat, 28 Apr 2012 18:17:49 -0400 Message-Id: <1335651473-19652-3-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+NgFtrEIsWRmVeSWpSXmKPExsUixCmqrDs9Z46/wZNlghbXb85kdmD0eLbq FnMAYxSXTUpqTmZZapG+XQJXxqyWO2wFV2Qrju19ztrAuFG8i5GTQ0LARGLB0gssELaYxIV7 69m6GLk4hAT2MUq837yXHcLZwCjx+PQNJpAqIYH7TBJtS7QhEvMZJfat/MsKkmAT0JDYtn85 I4gtIiAtsfPubKA4BwezgJrEny4VkLCwgL/Eoj8rmEFsFgFViYX/zoG18go4SLx+dogZ4goF iWfrjoPt4hRwlPi/+QQ7xF4HiY55E9gmMPIvYGRYxSibklulm5uYmVOcmqxbnJyYl5dapGuk l5tZopeaUrqJERw0krw7GN8dVDrEKMDBqMTDe2j9LH8h1sSy4srcQ4ySHExKorwsWXP8hfiS 8lMqMxKLM+KLSnNSiw8xSnAwK4nwaosD5XhTEiurUovyYVLSHCxK4ryqWu/8hATSE0tSs1NT C1KLYLIyHBxKErxHs4EaBYtS01Mr0jJzShDSTBycIMN5gIbvAanhLS5IzC3OTIfIn2JUlBLn XQ+SEABJZJTmwfXCovoVozjQK8K8Z0GqeIAJAa77FdBgJqDBTJ6zQAaXJCKkpBoYHVyFJVbr +u+a9DYvoy1dTHt7XlPF3JebLj+Z2vLKcWupmf5Zhudvp20vmu9t9ORbpfMc0wsPg8oPZa3h ZT+WEfozSFP7VpFwn+RytwaViC1z1VeZZxU+1Dz+d6u82FUDI+MYTavZuZO+vyh9U2ZSrPS9 e269gvvKM0l/7tbr/1n85pGTgsoGJZbijERDLeai4kQAETauQ8UCAAA= 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:01 -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 | 26 +++++++++++++++++++------- lib/notmuch.h | 8 ++++---- notmuch-new.c | 3 ++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index a29fe67..a3ae504 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,27 @@ 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; + *database = notmuch; + return status; } notmuch_status_t diff --git a/lib/notmuch.h b/lib/notmuch.h index 8a011f2..d880aeb 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -140,11 +140,11 @@ 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). */ -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