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 85163431FD9 for ; Thu, 19 Jul 2012 11:43:30 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] 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 bEHMKiv8Holr for ; Thu, 19 Jul 2012 11:43:27 -0700 (PDT) Received: from mail.bustany.org (bustany.org [176.31.244.208]) by olra.theworths.org (Postfix) with ESMTP id 35FF0431FC0 for ; Thu, 19 Jul 2012 11:43:27 -0700 (PDT) Received: from localhost.localdomain (91-158-2-79.elisa-laajakaista.fi [91.158.2.79]) by mail.bustany.org (Postfix) with ESMTPSA id F0D3D1400C3 for ; Thu, 19 Jul 2012 20:45:55 +0200 (CEST) From: Adrien Bustany To: notmuch@notmuchmail.org Subject: [PATCH 1/2] Add notmuch_database_flush method Date: Thu, 19 Jul 2012 21:43:20 +0300 Message-Id: <1342723401-26103-2-git-send-email-adrien@bustany.org> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1342723401-26103-1-git-send-email-adrien@bustany.org> References: <1342723401-26103-1-git-send-email-adrien@bustany.org> 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: Thu, 19 Jul 2012 18:43:30 -0000 This method explicitly flushes the pending modifications to disk. It is useful if your program has various threads, each with a read only DB and one writer thread with a read/write DB. In that case, you most likely want the writer to sync the changes to disk so that the readers can see them, without having to close and reopen the database completely. --- lib/database.cc | 18 ++++++++++++++++++ lib/notmuch.h | 4 ++++ 2 files changed, 22 insertions(+), 0 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 761dc1a..55bcd17 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -745,6 +745,24 @@ notmuch_database_open (const char *path, return status; } +notmuch_status_t +notmuch_database_flush(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) { + fprintf(stderr, "A Xapian exception occured flushing the database: %s\n", + error.get_msg().c_str()); + status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + } + + return status; +} + void notmuch_database_close (notmuch_database_t *notmuch) { diff --git a/lib/notmuch.h b/lib/notmuch.h index 3633bed..aef5c56 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -201,6 +201,10 @@ notmuch_database_open (const char *path, notmuch_database_mode_t mode, notmuch_database_t **database); +/* Flushes all the pending modifications to the database to disk. */ +notmuch_status_t +notmuch_database_flush (notmuch_database_t *database); + /* Close the given notmuch database. * * After notmuch_database_close has been called, calls to other -- 1.7.7.6