From: Peter Wang Date: Wed, 16 Apr 2014 12:59:16 +0000 (+1000) Subject: [PATCH v2 01/10] lib: add return status to database close and destroy X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3c3b24db53f73122cb4f039878e7cd3150be7d4e;p=notmuch-archives.git [PATCH v2 01/10] lib: add return status to database close and destroy --- diff --git a/c6/bb455792135b8d4efdfd79a5a31cb3ab6234c5 b/c6/bb455792135b8d4efdfd79a5a31cb3ab6234c5 new file mode 100644 index 000000000..395c5414b --- /dev/null +++ b/c6/bb455792135b8d4efdfd79a5a31cb3ab6234c5 @@ -0,0 +1,193 @@ +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 1C5AC431FAE + for ; Wed, 16 Apr 2014 05:59:53 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, 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 lxzgLNUZ5nxx for ; + Wed, 16 Apr 2014 05:59:45 -0700 (PDT) +Received: from mail-pb0-f48.google.com (mail-pb0-f48.google.com + [209.85.160.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id B9393431FBD + for ; Wed, 16 Apr 2014 05:59:45 -0700 (PDT) +Received: by mail-pb0-f48.google.com with SMTP id md12so10811001pbc.21 + for ; Wed, 16 Apr 2014 05:59:44 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:in-reply-to:references; + bh=sLA/eo+oalwo7mq/wx2zV958LJUsx3y51c3R8q57lOM=; + b=cczvDjyy/eSuq7dxhPSnzGtgfueFEYeUFb8TmzfkPPgw9hEO/p3cGZBQ/bhZfYOHzW + RTkj3CH55BdAaM1bU+3qbdB5VI516e3y+z72U7xuWpYl3hh+dLIQib/U0ClF7xCRt6Dc + NmugiUAZrnRW8v2/6mMLsbMCipA4j5xZvh++rpu4PQUfHoOhTDE51tNpTOlmMO0iaYmI + pwHPPfkmRspvTxXYpTb+80Uwu4LjSUzhgNEh6h6r/BZKJ97iltJoNzcH5Nb/U3cQFj3u + hI8KmID/UNJOoD/icBFBlDKftxzAn4nDL0/imMDmsnraU0ABZcUMqBgP2laIfPaexeXj + rjXQ== +X-Received: by 10.68.221.42 with SMTP id qb10mr8324273pbc.65.1397653183958; + Wed, 16 Apr 2014 05:59:43 -0700 (PDT) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPSA id ja8sm46975039pbd.3.2014.04.16.05.59.41 + for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Wed, 16 Apr 2014 05:59:43 -0700 (PDT) +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: [PATCH v2 01/10] lib: add return status to database close and destroy +Date: Wed, 16 Apr 2014 22:59:16 +1000 +Message-Id: <1397653165-15620-2-git-send-email-novalazy@gmail.com> +X-Mailer: git-send-email 1.8.4 +In-Reply-To: <1397653165-15620-1-git-send-email-novalazy@gmail.com> +References: <1397653165-15620-1-git-send-email-novalazy@gmail.com> +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: Wed, 16 Apr 2014 12:59:53 -0000 + +From: Jani Nikula + +notmuch_database_close may fail in Xapian ->flush() or ->close(), so +report the status. Similarly for notmuch_database_destroy which calls +close. + +This is required for notmuch insert to report error status if message +indexing failed. +--- + lib/database.cc | 30 ++++++++++++++++++++++++------ + lib/notmuch.h | 15 +++++++++++++-- + 2 files changed, 37 insertions(+), 8 deletions(-) + +diff --git a/lib/database.cc b/lib/database.cc +index 1efb14d..ef7005b 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -774,14 +774,17 @@ notmuch_database_open (const char *path, + return status; + } + +-void ++notmuch_status_t + notmuch_database_close (notmuch_database_t *notmuch) + { ++ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; ++ + try { + if (notmuch->xapian_db != NULL && + notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE) + (static_cast (notmuch->xapian_db))->flush (); + } catch (const Xapian::Error &error) { ++ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + if (! notmuch->exception_reported) { + fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n", + error.get_msg().c_str()); +@@ -795,7 +798,9 @@ notmuch_database_close (notmuch_database_t *notmuch) + try { + notmuch->xapian_db->close(); + } catch (const Xapian::Error &error) { +- /* do nothing */ ++ /* don't clobber previous error status */ ++ if (status == NOTMUCH_STATUS_SUCCESS) ++ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + } + } + +@@ -809,6 +814,8 @@ notmuch_database_close (notmuch_database_t *notmuch) + notmuch->value_range_processor = NULL; + delete notmuch->date_range_processor; + notmuch->date_range_processor = NULL; ++ ++ return status; + } + + #if HAVE_XAPIAN_COMPACT +@@ -972,8 +979,15 @@ notmuch_database_compact (const char *path, + } + + DONE: +- if (notmuch) +- notmuch_database_destroy (notmuch); ++ if (notmuch) { ++ notmuch_status_t ret2; ++ ++ ret2 = notmuch_database_destroy (notmuch); ++ ++ /* don't clobber previous error status */ ++ if (ret == NOTMUCH_STATUS_SUCCESS && ret2 != NOTMUCH_STATUS_SUCCESS) ++ ret = ret2; ++ } + + talloc_free (local); + +@@ -991,11 +1005,15 @@ notmuch_database_compact (unused (const char *path), + } + #endif + +-void ++notmuch_status_t + notmuch_database_destroy (notmuch_database_t *notmuch) + { +- notmuch_database_close (notmuch); ++ notmuch_status_t status; ++ ++ status = notmuch_database_close (notmuch); + talloc_free (notmuch); ++ ++ return status; + } + + const char * +diff --git a/lib/notmuch.h b/lib/notmuch.h +index 350bed8..3c5ec98 100644 +--- a/lib/notmuch.h ++++ b/lib/notmuch.h +@@ -287,8 +287,16 @@ notmuch_database_open (const char *path, + * + * notmuch_database_close can be called multiple times. Later calls + * have no effect. ++ * ++ * Return value: ++ * ++ * NOTMUCH_STATUS_SUCCESS: Successfully closed the database. ++ * ++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred; the ++ * database has been closed but there are no guarantees the ++ * changes to the database, if any, have been flushed to disk. + */ +-void ++notmuch_status_t + notmuch_database_close (notmuch_database_t *database); + + /** +@@ -317,8 +325,11 @@ notmuch_database_compact (const char* path, + /** + * Destroy the notmuch database, closing it if necessary and freeing + * all associated resources. ++ * ++ * Return value as in notmuch_database_close if the database was open; ++ * notmuch_database_destroy itself has no failure modes. + */ +-void ++notmuch_status_t + notmuch_database_destroy (notmuch_database_t *database); + + /** +-- +1.8.4 +