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 3DCA5431FC0 for ; Sun, 19 Jan 2014 09:21:02 -0800 (PST) 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 RW3jJQhRq-c9 for ; Sun, 19 Jan 2014 09:20:53 -0800 (PST) Received: from mail-ea0-f180.google.com (mail-ea0-f180.google.com [209.85.215.180]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 24FE8431FBD for ; Sun, 19 Jan 2014 09:20:53 -0800 (PST) Received: by mail-ea0-f180.google.com with SMTP id f15so2654834eak.39 for ; Sun, 19 Jan 2014 09:20:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FM78c4W+E5Vv6uxqS07KLcar+lVzJdx9zl+rOiS8Okw=; b=KZh6682lEtKeNiWJydd6PD4tGLSrEDvH3Stmp5zYzvi3uMFXtuqUYCHZSlEvt0JcgM i5k9NeWp9YZLak4OBsCAt9OB5XOX0Bod3oi25cZYhHkBciIphQHGpKWfmU6w/hfKXwgv ZRGLsTwtvSArla4G4S+kRkzGGuYCopf6AoY6AIM2xBy/31BqyD//qM+e3bPl/vhD3/Jt Ckf6T+iQzmH9eIZsP2i6TQwZcMrUIpzJQRFs1421ooDbIB6PKR3FA0QBDbyR+6nVkc5/ Giu7Yhmf6pu/5BAuD14fSOenSOTuNc2Hl3xqRuwroBEy3fUtovf/u2pr6Zbb5YbrBaAB z8pQ== X-Gm-Message-State: ALoCoQl0dfncpSZUdqwSLNHe6FqKkGS9lTPIYK+B6uOAnUAC+SNhRVsbs1NNQ5v4EvFNip7ZRYYc X-Received: by 10.14.114.70 with SMTP id b46mr203478eeh.84.1390152049132; Sun, 19 Jan 2014 09:20:49 -0800 (PST) Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. [88.195.111.91]) by mx.google.com with ESMTPSA id o47sm45284052eem.21.2014.01.19.09.20.47 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 19 Jan 2014 09:20:48 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v2] lib: add return status to database close and destroy Date: Sun, 19 Jan 2014 19:20:46 +0200 Message-Id: <1390152046-6509-1-git-send-email-jani@nikula.org> X-Mailer: git-send-email 1.8.5.2 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: Sun, 19 Jan 2014 17:21:02 -0000 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. --- v2 of id:29b808bb6bf051fe21b6a72f12bb4ad1badfbf97.1385903109.git.jani@nikula.org picked out of the series. --- 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 f395061..46a9a8f 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -767,14 +767,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()); @@ -788,7 +791,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; } } @@ -802,6 +807,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 @@ -965,8 +972,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); @@ -984,11 +998,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 02604c5..7ac7118 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.5.2