From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 2DD106DE1D82 for ; Thu, 23 Feb 2017 18:00:59 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=0.006, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MlPLOAzXTgys for ; Thu, 23 Feb 2017 18:00:58 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 23E026DE1D76 for ; Thu, 23 Feb 2017 18:00:57 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1ch5BA-0004PL-TV; Thu, 23 Feb 2017 21:00:16 -0500 Received: (nullmailer pid 10760 invoked by uid 1000); Fri, 24 Feb 2017 02:00:52 -0000 From: David Bremner To: David Bremner , Gaute Hope , notmuch@notmuchmail.org Subject: [RFC patch 1/2] lib: add notmuch_database_reopen Date: Thu, 23 Feb 2017 22:00:47 -0400 Message-Id: <20170224020048.10718-1-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <87y3wx2k3s.fsf@tethera.net> References: <87y3wx2k3s.fsf@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 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: Fri, 24 Feb 2017 02:00:59 -0000 The main expected use is to recover from a Xapian::DatabaseChanged exception. --- lib/database.cc | 19 +++++++++++++++++++ lib/notmuch.h | 12 ++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/database.cc b/lib/database.cc index 386dcd17..9c4be516 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1133,6 +1133,25 @@ notmuch_database_close (notmuch_database_t *notmuch) return status; } +notmuch_status_t +notmuch_database_reopen (notmuch_database_t *notmuch) +{ + if (notmuch->mode != NOTMUCH_DATABASE_MODE_READ_ONLY) + return NOTMUCH_STATUS_UNSUPPORTED_OPERATION; + + try { + notmuch->xapian_db->reopen (); + } catch (const Xapian::Error &error) { + if (! notmuch->exception_reported) { + _notmuch_database_log (notmuch, "Error: A Xapian exception reopening database: %s\n", + error.get_msg ().c_str ()); + notmuch->exception_reported = TRUE; + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + } + } + return NOTMUCH_STATUS_SUCCESS; +} + static int unlink_cb (const char *path, unused (const struct stat *sb), diff --git a/lib/notmuch.h b/lib/notmuch.h index 16da8be9..e9ed01dd 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -363,6 +363,18 @@ notmuch_status_t notmuch_database_close (notmuch_database_t *database); /** + * Reopen a (read-only) database, synching the database view with that + * on disk. + * + * @returns + * - NOTMUCH_STATUS_UNSUPPORTED_OPERATION: database is not read only + * - NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured trying to + * re-open the database. + */ +notmuch_status_t +notmuch_database_reopen (notmuch_database_t *database); + +/** * A callback invoked by notmuch_database_compact to notify the user * of the progress of the compaction process. */ -- 2.11.0